Skip to content

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

@ParanoikCZE

Description

@ParanoikCZE

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-dotnet.NET BindingsI-defectSomething is not working as intendedJ-awaiting answerQuestion asked of user; a reply moves it to triage again

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions