Skip to content Skip to sidebar Skip to footer

Movetargetoutofboundsexception Problem With Chromedriver Version >74

I don't know why ActionChains move_to_element() is not working with chromedriver >74. (But it works on chromedriver 74 and geckodriver.) Even though I add these three line befor

Solution 1:

As your use is to invoke click() through ActionChains instead of presence_of_element_located() and visibility_of_element_located() you need to use the expected_conditions as element_to_be_clickable() as follows:

  • Usage with ActionChains:

    ActionChains(driver).move_to_element(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "element_css")))).click().perform()
    
  • If you have to scrollIntoView() before invoking click() you need to induce WebDriverWait for the visibility_of_element_located() and you can use the following Locator Strategy:

    WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, xxxxx))
    drvier.execute_script("arguments[0].scrollIntoView();", WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, xxxxx)))
    ActionChains(driver).move_to_element(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "element_css")))).click().perform()
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.uiimportWebDriverWaitfrom selenium.webdriver.common.byimportByfrom selenium.webdriver.supportimport expected_conditions asEC

Additional Considerations

Ensure that:

  • Selenium is upgraded to current levels Version 3.141.59.
  • ChromeDriver is updated to current ChromeDriver v79.0.3945.36 level.
  • Chrome is updated to current Chrome Version 79.0 level. (as per ChromeDriver v79.0 release notes)
  • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
  • If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.
  • Take a System Reboot.
  • Execute your @Test as non-root user.
  • Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.

Update

As per your comments that:

options.add_experimental_option('w3c', False)

worked for you, but as per the Release Notes of ChromeDriver 75.0.3770.8:

Resolved issue 2536: Make standards mode (goog:chromeOptions.w3c:true) the default [Pri-2]

ChromeDriver 75.0 solves this issue.

So the bottom line is, chromeOptions.w3c needs to be set as true by default. It will be against the best practices to turn off w3c in chromedriver to address the error. We have discussed this in length and breadth in the following discussions:

Solution 2:

move_to_element uses internally move_to

defmove_to_element(self, to_element):
    if self._driver.w3c: # default in chromedriver 79
        self.w3c_actions.pointer_action.move_to(to_element)

defmove_to(self, element, x=None, y=None):
    #...
    el_rect = element.rect
    left_offset = el_rect['width'] / 2
    top_offset = el_rect['height'] / 2
    left = -left_offset + (x or0)
    top = -top_offset + (y or0)

    self.source.create_pointer_move(origin=element, x=int(left), y=int(top))

The mouse pointer is moved by offset based on the element position. You are locating the element and then scroll it into view using JavaScript, so the offset is calculated by the wrong coordinates.

Removing the JavaScript scroll should solve the problem.

Post a Comment for "Movetargetoutofboundsexception Problem With Chromedriver Version >74"