51Testing软件测试论坛

标题: Python+Selenium鼠标悬停报错,求大神指点一下 [打印本页]

作者: 一个小测试    时间: 2018-9-15 23:51
标题: Python+Selenium鼠标悬停报错,求大神指点一下
代码如下:
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
driver=webdriver.Ie()
driver.implicitly_wait(10)
driver.get("http://www.baidu.com")
link=driver.find_element_by_link_text("设置")
#鼠标悬停在百度“设置”上
ActionChains(driver).move_to_element(link).perform()
driver.find_element_by_link_text("搜索设置").clear()
driver.find_element_by_class_name("prefpanelgo").clear()

目的是想鼠标悬浮百度首页“设置”处
运行之后并没有悬停在设置处
报错如下:
Traceback (most recent call last):
  File "D:/python/test.py", line 7, in <module>
    ActionChains(driver).move_to_element(link).perform()
  File "D:\Tool\python370\Python\Python37\lib\site-packages\selenium\webdriver\common\action_chains.py", line 80, in perform
    self.w3c_actions.perform()
  File "D:\Tool\python370\Python\Python37\lib\site-packages\selenium\webdriver\common\actions\action_builder.py", line 76, in perform
    self.driver.execute(Command.W3C_ACTIONS, enc)
  File "D:\Tool\python370\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 320, in execute
    self.error_handler.check_response(response)
  File "D:\Tool\python370\Python\Python37\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.MoveTargetOutOfBoundsException: Message: The requested mouse movement to (1781, 16) would be outside the bounds of the current view port (left: 0, right: 1536, top: 79, bottom: 824)

作者: cq520131517    时间: 2018-9-17 09:09
中间加个时间等待试下

作者: NancyWangDL    时间: 2018-9-17 14:31
可以参考下博客:https://www.cnblogs.com/android-it/p/9371944.html,跟你写的差不多,你的报错猜测:是不是因为没有最大化你的ie导致定位找不到?个人猜测




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2