MoveTargetOutOfBoundsException problem with chromedriver version >74 MoveTargetOutOfBoundsException problem with chromedriver version >74 selenium selenium

MoveTargetOutOfBoundsException problem with chromedriver version >74


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.ui import WebDriverWaitfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support import expected_conditions as EC

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:


move_to_element uses internally move_to

def move_to_element(self, to_element):    if self._driver.w3c: # default in chromedriver 79        self.w3c_actions.pointer_action.move_to(to_element)def move_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 or 0)    top = -top_offset + (y or 0)    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.