Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FindElement() for number strings not working Eg: driver.FindElement(By.Name("2")).Click(); #99

Closed
lagori opened this issue Oct 1, 2024 · 2 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@lagori
Copy link

lagori commented Oct 1, 2024

Hi,

While finding an element with number string eg: driver.FindElement(By.Name("2")).Click();
is giving and error as below:
Error Message:
OpenQA.Selenium.WebDriverException : Selector strategy 'css selector' with value '*[name ="\32 "]' is not supported
Stack Trace:
at OpenQA.Selenium.WebDriver.UnpackAndThrowOnError(Response errorResponse, String commandToExecute)
at OpenQA.Selenium.WebDriver.ExecuteAsync(String driverCommandToExecute, Dictionary2 parameters) at OpenQA.Selenium.WebDriver.Execute(String driverCommandToExecute, Dictionary2 parameters)
at OpenQA.Selenium.WebDriver.FindElement(String mechanism, String value)
at OpenQA.Selenium.By.<.ctor>b__11_0(ISearchContext context)
at OpenQA.Selenium.By.FindElement(ISearchContext context)
at OpenQA.Selenium.WebDriver.FindElement(By by)
at FlaSelOne.POApprove.POApproveTest() in D:\KitePack\POC\CS\FlaUISelenium\FlaSelOne\POApprove.cs:line 48
at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

I tried with the escape sequence as well but had no luck.

The Inspect screenshot -
image

@aristotelos
Copy link
Collaborator

That is weird, I would not expect a \3 in that error message *[name ="\32 "].

It could be that the SimpleCssAttributeRegex (which is not so simple) does not work correctly. I'll check. See

private static Regex SimpleCssAttributeSelectorRegex = new Regex(@"^\*?\[\s*(?<ident>-?(?<nmstart>[_a-z]|[\240-\377])(?<nmchar>[_a-z0-9-]|[\240-\377])*)\s*=\s*(?<string>(?<string1>""(?<string1value>([^\n\r\f\\""]|(?<escape>\\[^\r\n\f0-9a-f]))*)"")|(?<string2>'(?<string2value>([^\n\r\f\\']|(?<escape>\\[^\r\n\f0-9a-f]))*)'))\s*\]$", RegexOptions.Compiled | RegexOptions.IgnoreCase);

@aristotelos aristotelos added bug Something isn't working good first issue Good for newcomers labels Oct 2, 2024
@aristotelos
Copy link
Collaborator

Hi @lagori , this seems to be an issue in the Selenium .NET client that translates By.Name("2") into *[name ="\32 "]. Could you log this issue at https://github.com/SeleniumHQ/selenium/issues?

See https://github.com/SeleniumHQ/selenium/blob/0fe28e300f0fdc88b07cb3421fb303b4a8e42a8e/dotnet/src/webdriver/By.cs#L393

aristotelos added a commit that referenced this issue Oct 4, 2024
Add a unit test project and add a few small unit tests related to #99,
which prove that this is not an issue in FlaUI.WebDriver.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants