[🐛 Bug]: InvalidSelectorException is handled differently in Java & C# / Python bindings
What happened?
The InvalidSelectorException in Java derives from NoSuchElementException, a FluentWait will retry until the timeout is reached. The InvalidSelectorException in C# derives from NoSuchElementException, a WebDriverWait will retry until the timeout is reached. The InvalidSelectorException in Python derives from WebDriverException, a wait will instantly fail.
This is confusing in my mind, is it correct to derive InvalidSelectorException from NoSuchElementException? Will a invalid selector, repair it self over time?
How can we reproduce the issue?
search By.xpath("]") using a FluentWait / WebDriverWait / wait
Relevant log output
N/A
Operating System
Windows 10 x64
Selenium version
4.x.x
What are the browser(s) and version(s) where you see this issue?
N/A
What are the browser driver(s) and version(s) where you see this issue?
N/A
Are you using Selenium Grid?
No response
@joerg1985, thank you for creating this issue. We will troubleshoot it as soon as we can.
Info for maintainers
Triage this issue by using labels.
If information is missing, add a helpful comment and then I-issue-template label.
If the issue is a question, add the I-question label.
If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.
If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C),
add the applicable G-* label, and it will provide the correct link and auto-close the
issue.
After troubleshooting the issue, please add the R-awaiting answer label.
Thank you!
Hi @joerg1985 thanks for the issue, polling on an invalid selector is in my opinion not correct and I think python is correct here (it recently changed IIRC via @titusfortner) - I would like to see what the other folks think of the other bindings here.
An invalid selector should never be waited for as it will always be invalid and fail. This is an excellent reason for the error not to be implemented as a subclass of no such element, even though it was not the reason I made the change in Python. The reason I broke them apart is because it doesn't make sense to get a NoSuchElementException when executing a find_elements() method, which is what can happen when you make it a subclass.
I didn't look at Java or .NET when I made the change (and I should have). Ruby has never had it as a subclass. Java made it a subclass to maintain backwards compatibility with what existed before the exception was created in the firefox driver in 2011. Looks like .NET started without the subclass, but then changed to match Java in 2014 (no reason given in commit message).
I think it should be changed in Java & .NET as well. I can't think of a good reason for it to be treated the same way except for backwards compatibility.
It was agreed at Aug 17 TLC meeting that we will write a blog post about this and make the change.
Reopening because we need to do this in the other bindings.
Fine in Ruby — https://github.com/SeleniumHQ/selenium/blob/trunk/rb/lib/selenium/webdriver/common/error.rb#L135
We changed this in Python last year — https://github.com/SeleniumHQ/selenium/commit/2d9cf16c29bd4e6b98d886b79651957b55ea5d17
Looks like it is good in JS — https://github.com/SeleniumHQ/selenium/blob/trunk/javascript/node/selenium-webdriver/lib/error.js#L146
So, just need to update in .NET — https://github.com/SeleniumHQ/selenium/blob/trunk/dotnet/src/webdriver/InvalidSelectorException.cs#L28
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.