selenium icon indicating copy to clipboard operation
selenium copied to clipboard

[🐛 Bug]: Unable to cast object String to Boolean in WebElement.Displayed

Open ParanoikCZE opened this issue 3 years ago • 3 comments

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 avatar Jun 10 '22 10:06 ParanoikCZE

@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!

github-actions[bot] avatar Jun 10 '22 10:06 github-actions[bot]

Would you like to send us a PR?

diemol avatar Jun 10 '22 11:06 diemol

Would you like to send us a PR?

If my proposed solution is fine for you, but I'm not sure about other languages.

ParanoikCZE avatar Jun 10 '22 12:06 ParanoikCZE

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.

keraymundo10 avatar Oct 05 '22 03:10 keraymundo10

I'm on W10.

ParanoikCZE avatar Oct 05 '22 08:10 ParanoikCZE

@nvborisenko can you help us take a look at this issue? We discussed solutions in https://github.com/SeleniumHQ/selenium/pull/10763

titusfortner avatar Apr 18 '23 15:04 titusfortner

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.

nvborisenko avatar Apr 18 '23 22:04 nvborisenko

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.

github-actions[bot] avatar Dec 09 '23 00:12 github-actions[bot]