question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[🐛 Bug]: SelectElement not working after updating selenium webdriver 4 and IEDriverServer 4

See original GitHub issue

What happened?

after updating selenium WebDriver (3.15 to 4.0.0) and IEDriver (3.150.1 to 4.0.0) getting below error while setting dropdown value, code was working properly with old selenium version (3): Error : Cannot click on option element. Executing JavaScript click function returned an unexpected error, but no error could be returned from Internet Explorer’s JavaScript engine

HTML :

<SELECT id=selCountry"> <OPTION selected value=0>None</OPTION> <OPTION value=1>India</OPTION></SELECT>

C# code : public By countrySelector = By.Id(“selCountry”); public string Country { set => new SelectElement(Driver.FindElement(countrySelector )).SelectByText(value); }

   Country= "India";

How can we reproduce the issue?

HTML : 
<TD vAlign=top><SELECT id=selCountry">
<OPTION selected value=0>None</OPTION> <OPTION value=1>India</OPTION></SELECT>
</TD>
       

 public By countrySelector = By.Id("selCountry");

        public string Country
        {
            set => new SelectElement(Driver.FindElement(countrySelector )).SelectByText(value);
        }

Country= "India";

Relevant log output

Cannot click on option element. Executing JavaScript click function returned an unexpected error, but no error could be returned from Internet Explorer's JavaScript engine

Operating System

Window server 2016

Selenium version

C# Selenium version 4 , IEDriver 4

What are the browser(s) and version(s) where you see this issue?

Internet Explorer 11

What are the browser driver(s) and version(s) where you see this issue?

IEDriver 4

Are you using Selenium Grid?

no

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:50 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
RNDanielcommented, May 2, 2022

I found a solution! Use JavaScriptExecutor.

Selenium Webdriver version : 4.1.3 IEDriver version : 4.0.0

 public void selectOption(WebDriver wdriver,WebElement wele,String value) throws Exception {
      JavascriptExecutor jexec = (JavascriptExecutor) wdriver;
      jexec.executeScript("var select = arguments[0]; for(var i = 0; i < select.options.length; i++){ if(select.options[i].text == arguments[1]){ select.options[i].selected = true; } }", wele, value);
  }

  public void deselectOption(WebDriver wdriver,WebElement wele) throws Exception {
      JavascriptExecutor jexec = (JavascriptExecutor) wdriver;
      jexec.executeScript("var select = arguments[0]; for(var i = 0; i < select.options.length; i++){ select.options[i].selected = false; } ", wele);
	}
	
■Samlple exec code
WebElement sitem = windowDriver.findElement(By.xpath("//select[@name='itemSel']"));
selectOption(windowDriver, sitem, "test object");

Thank you very much you are an angel. I’m working in a bank too with a very old system and I couldn’t do my job because of this bug. I wrote it in python and this finally works for me.

0reactions
github-actions[bot]commented, Jun 4, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

C# with Selenium: "SelectElement" does not exist in the ...
The error says: "SelectElement" does not exist in the current context. IWebDriver myDriver = new ChromeDriver(); IWebElement currency = myDriver ...
Read more >
Migrating to Selenium 4: Here's What Has Changed - Applitools
A guide to notable changes and deprecations for engineers looking to migrate from Selenium 3 to Selenium 4. There is huge excitement within ......
Read more >
Chrome Driver Issue while executing Selenium Tests
Hi all, I am executing some Selenium tests and I am getting the below error now.It was working fine until yesterday with same...
Read more >
[Code example]-Selenium .net SelectElement Options, what is the ...
I'm not sure why you are using var instead of the specific data types. This works for me. public static IList<IWebElement> GetSelectListByID(string ...
Read more >
java/CHANGELOG - external/github.com/SeleniumHQ/selenium - Git ...
Fix an error propagation bug when a command fails from bad inputs. ... Bump timeout for tests since a suite is also a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found