[🐛 Bug]: Unable to cast object String to Boolean in WebElement.Displayed
What happened?
I've observed this issue only a few times but gave it a shot with the investigation. I've tracked it to https://github.com/SeleniumHQ/selenium/blob/trunk/dotnet/src/webdriver/WebElement.cs#L188
Not sure what cames here, as it's almost impossible to reproduce, but pretty clearly there could come kind of exception or another kind of unexpected message and cast fails, so I recommend changing this part of the code to something like: var res = bool.TryParse(commandResponse.Value, out bool result); return res ? result : false;
How can we reproduce the issue?
Observed in ~1/100000 cases so there is no simple way to do this. Code used when observed:
new WebDriverWait(driver, new TimeSpan(0, 0, 30)).Until(ExpectedConditions.ElementIsVisible(by));
The checked element is a button in the dropdown menu which might be caught in a kind of "construction" state so it's possible that called js doesn't exist and returns an 'undefined' result.
Relevant log output
System.InvalidCastException : Unable to cast object of type 'System.String' to type 'System.Boolean'.
--InvalidCastException
at OpenQA.Selenium.WebElement.get_Displayed()
at SeleniumExtras.WaitHelpers.ExpectedConditions.<>c__DisplayClass20_0.<ElementToBeClickable>b__0(IWebDriver driver)
at OpenQA.Selenium.Support.UI.DefaultWait`1.Until[TResult](Func`2 condition, CancellationToken token)
at OpenQA.Selenium.Support.UI.DefaultWait`1.Until[TResult](Func`2 condition)
Operating System
Azure devops
Selenium version
C# 4.1.1
What are the browser(s) and version(s) where you see this issue?
Chrome 102.0.5005.63
What are the browser driver(s) and version(s) where you see this issue?
101.0.4951.4100
Are you using Selenium Grid?
4.1.4
@ParanoikCZE, 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!
Would you like to send us a PR?
Would you like to send us a PR?
If my proposed solution is fine for you, but I'm not sure about other languages.
Hi @ParanoikCZE, just wondering which Windows version are the tests executing against? Is it Windows 11? Thanks! I am encountering the same error against Windows 11. but works fine against Windows 10.
I'm on W10.
@nvborisenko can you help us take a look at this issue? We discussed solutions in https://github.com/SeleniumHQ/selenium/pull/10763
Proposed very simple PR https://github.com/SeleniumHQ/selenium/pull/11913 to get more clarity what was going wrong, rather than trying to ignore hidden bug.
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.