首页 > 解决方案 > 尝试使用 Selenium 自动登录亚马逊但收到 JavaScript 错误

问题描述

我正在尝试使用 Selenium 自动登录亚马逊,但出现 JavaScript 错误。下面的代码给出了下面的错误,如何解决这个问题?

options = webdriver.ChromeOptions()
options.add_argument("--start-maximized")
driver = webdriver.Chrome()
action = ActionChains(driver)
time.sleep(1)

driver.get('http://www.amazon.in')
time.sleep(3)

firstLevelMenu = driver.find_element_by_xpath('//*[@id="nav-link-accountList"]/span[2]')
 driver.implicitly_wait(3)
 action.move_to_element(firstLevelMenu).perform()
 time.sleep(3)

出现错误"action.move_to_element(firstLevelMenu).perform()"

selenium.common.exceptions.JavascriptException: Message:
javascript error: Failed to execute  'elementsFromPoint' on
'Document': The provided double value is non-finite. (Session info:
chrome=86.0.4240.75)** 

标签: seleniumautomationautomated-testsselenium-chromedriver

解决方案


这是打开该帐户选项卡的方法。

driver.get('http://www.amazon.in')
try:
    firstLevelMenu =WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, "#nav-link-accountList")))
    action = ActionChains(driver)
    action.move_to_element(firstLevelMenu).perform()
except Exception as e: 
    print(e)

进口

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC

推荐阅读