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

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

About this issue

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

Most upvoted comments

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.