0

While running the Python code on Edge browser in IE mode get the 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"

This code:

def my_select(self, text):
    self.app.select_from_drop_down('//select[@class="gender"]', text)

calls this one:

def select_from_drop_down(self, selector, text):
    wd = self.wd
    if text is not None:
        Select(wd.find_element(By.XPATH, selector)).select_by_visible_text(text)

and in the test I call the my_select method:

def test_select_male(app):
    app.people_page.open_page()
    app.people_page.my_select('Male')

DOM:

                      <select class="gender">
                         <option></option>
                         <option name="MALE">Male</option>
                         <option name="FEMALE">Female</option>
                      </select>

This is a know bug, that was reported to selenium developers. But it's not fixed. https://github.com/SeleniumHQ/selenium/issues/10319 People have found work around for Java and published it in the comments.

I have tried to write a work around for this bug in Python using execute_script, but never succeeded.

def select_from_drop_down_menu(self):
    btn = wd.find_element(By.XPATH, '//select[@name="MALE"]').click()
    wd.execute_script("arguments[0].click();", btn)

Thanks for your help!

piersto
  • 1
  • 1

1 Answers1

0

You can take help of the execute_script() method as follows:

def select_from_drop_down(self, selector, text):
    wd = self.wd
    if text is not None:
     wd.execute_script("arguments[0].click();", wd.find_element(By.XPATH, selector))
     

And you can continue calling it as:

def test_select_male(app):
    app.people_page.open_page()
    app.people_page.my_select('Male')
    

and further:

def my_select(self):
    self.app.select_from_drop_down('//select[@class="gender"]//option[text()='Male']', text)
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Hi! The test passes, I mean no errors displayed, but the drop down is not clicked and option is not selected. :( – piersto Feb 09 '23 at 18:07