chromedriver版本> 74的MoveTargetOutOfBoundsException问题

chromedriver版本> 74的MoveTargetOutOfBoundsException问题

问题描述:

我不知道为什么ActionChains move_to_element()无法与chromedriver> 74一起使用.

I don't know why ActionChains move_to_element() is not working with chromedriver >74.

(但它适用于chromedriver 74和geckodriver.)

即使我在ActionChains之前添加了这三行,它仍然无法移至element.

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()

并抛出如下错误:

selenium.common.exceptions.MoveTargetOutOfBoundsException:消息: 将目标移出边界(会话信息:chrome = 79.0.3945.117)

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

即使在滚动到元素之后,我也尝试使用 Selenium MoveTargetOutOfBoundsException中提到的move_to_element_with_offset ,它仍然无法正常工作:

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()

以下是我对chromedriver的设置. 设置对ActionChains有影响吗?

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)

由于您要通过 ActionChains 而不是presence_of_element_located()visibility_of_element_located()调用click(),因此需要使用 expected_conditions 作为 element_to_be_clickable() 如下:

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:

  • ActionChains 一起使用:

ActionChains(driver).move_to_element(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "element_css")))).click().perform()

  • 如果在调用click()之前必须先scrollIntoView(),则需要为visibility_of_element_located()引入 WebDriverWait ,并且可以使用以下

  • 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
    

  • 确保:

    • 已升级到当前级别版本3.141.59 .
    • ChromeDriver 已更新为当前的 ChromeDriver v79.0.3945.36 级别.
    • Chrome 已更新为当前的 Chrome版本79.0 级别. (根据 ChromeDriver v79.0发行说明)
    • 通过 IDE
    • 清理您的项目工作区重建您的项目,并且仅具有必需的依赖项.
    • 如果您的基本 Web客户端版本太旧,请通过来卸载. Revo Uninstaller 并安装最新版本的 Web客户端 GA和发行版.
    • 进行系统重启.
    • 非root用户用户的身份执行@Test.
    • 始终在tearDown(){}方法中调用driver.quit()以关闭&优雅地销毁 WebDriver Web Client 实例.
    • 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.

    根据您的评论:

    options.add_experimental_option('w3c', False)
    

    为您工作,但根据

    已解决的问题2536:将标准模式(goog:chromeOptions.w3c:true)设置为默认的[Pri​​-2]

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

    ChromeDriver 75.0 解决了此问题.

    ChromeDriver 75.0 solves this issue.

    因此,最重要的是,默认情况下需要将chromeOptions.w3c设置为 true .在 chromedriver 中关闭w3c以解决该错误是违反最佳做法的.在以下讨论中,我们在长度和宽度上进行了讨论:

    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:

    • How to turn off w3c in chromedriver to address the error unknown command: Cannot call non W3C standard command while in W3C
    • Cannot call non W3C standard command while in W3C mode (Selenium::WebDriver::Error::UnknownCommandError) with Selenium ChromeDriver in Cucumber Ruby