【报错】python使用selenium库时报错:MoveTargetOutOfBoundsException: Message: move target out of bounds

问题:

使用selenium库时报错:MoveTargetOutOfBoundsException: Message: move target out of bounds

修改前代码:
from selenium import webdriver
driver = webdriver.Chrome(executable_path = r'D:\Chrome Chrome\Google\Chrome\Application\chromedriver.exe') #driver的路径
driver.get("http://edu.cstor.cn/#")  #打开网站

ac = driver.find_element_by_xpath('//*[@id="app"]/div/div[1]/div/div/div/div/span[1]') #元素的XPath
ActionChains(driver).move_to_element(ac).click(ac).perform() #将鼠标移动到元素位置并单击
原因:

要寻找的元素不在视野范围内

解决方法:

把窗口最大化,用driver.maximize_window()

修改后代码:

(修改在第4行)

from selenium import webdriver
driver = webdriver.Chrome(executable_path = r'D:\Chrome Chrome\Google\Chrome\Application\chromedriver.exe')#driver的路径
driver.get("http://edu.cstor.cn/#")  #打开网站
driver.maximize_window() #窗口最大化(不然找不到"登录")

ac = driver.find_element_by_xpath('//*[@id="app"]/div/div[1]/div/div/div/div/span[1]') ##元素的XPath
ActionChains(driver).move_to_element(ac).click(ac).perform()  #将鼠标移动到某个元素的位置并单击
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值