1

I solved this issue with the following code, I didn't find a solution in other posts so I tried to make myself and worked just fine. I don't now if it's a good code because I'm new in Python and programming but it worked.

As I wanted to select the element using visible text (not by value or option number), I used the following code, which consist in finding the element by Xpath [contains(text(), 'text')] and then changing the html. Maybe it's useful for another one.

self.driver.execute_script(
    "arguments[0].selected=true",
    self.driver.find_element_by_xpath(
        '//*[contains(text(), "%s" )]' % 'your_visible_text'
    ),
)
jajb
  • 105
  • 7

1 Answers1

0

this issue usually occurs in chrome browser as chrome uses point location. this happens when element is loaded in DOM but postion not fixed on UI. There can be certains solutions you could use to fix this:

  1. Wait:

    Use of WebDriverwait and Expected Conditions classes.

    Eg:

    visiblityOfElementLocated(By locator)

    or

    visibilityOf(WebElement element)

    we are waiting for element to be present and visible before performing action

  2. try to maximise the browser window before selecting dropdown

    driver .manage().window().maximize();

Hope this help. Code is using Java selenium please use its corresponding Python code.

APa
  • 18
  • 1
  • 6
  • I've already used visibility_of_element_located & element_to_be_clickable as EC. Both conditions are passed, also, if I check them separately I get True. I'm using geckodriver. I solved the problem temporarily using FirefoxOptions --headless – jajb Jun 05 '19 at 15:24