Search code examples
pythonseleniumactionwebdriverwaitjs-scrollintoview

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 before ActionChains, it still failed to move to element.

WebDriverWait(driver, 60).until(EC.presence_of_element_located((By.XPATH, xxxxx)))
WebDriverWait(driver, 60).until(EC.visibility_of_element_located((By.XPATH, xxxxx))
drvier.execute_script("arguments[0].scrollIntoView();", element)

ActionChains(driver).move_to_element(element).click().perform()

And throw error as below:

selenium.common.exceptions.MoveTargetOutOfBoundsException: Message: move target out of bounds (Session info: chrome=79.0.3945.117)

I also try to use move_to_element_with_offset mentioned in Selenium MoveTargetOutOfBoundsException even after scrolling to element, it still not working:

ActionChains(driver).move_to_element_with_offset(element, 5, 5).click().perform()

Below is my setting of chromedriver. Is there any settings impact to ActionChains?

options = webdriver.ChromeOptions()
options.add_argument('--no-sandbox')
options.add_argument('log-level=3')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--no-proxy-server')
options.add_argument('--disable-extensions')
options.add_argument('--disable-infobars')
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(executable_path=chromedriver_path, chrome_options=options)

Solution

  • 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 WebDriverWait
      from selenium.webdriver.common.by import By
      from 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: