首页 > 其他 > 详细

[selenium]selenium.common.exceptions.MoveTargetOutOfBoundsException的处理

时间:2020-03-23 09:08:14      阅读:506      评论:0      收藏:0      [点我收藏+]

在做selenium爬虫的时候,点击链接,发现总提示这个错误selenium.common.exceptions.MoveTargetOutOfBoundsException

后来查询,发现这可能是selenium在Firefox运行上的BUG,

ActionChains(self.firefox).move_to_element(text_wrap).click(text_wrap).perform()
move_to_element方法并没有像我们想象那样将FIREFOX滚动到我们的对象所在位置,因而,当我们要操作的element不在窗口显示范围时,就会报错。
然后在网上找了个简单粗暴的方法,滚动到我们的element
def _scorll_to_element_by_js(self, tag):
        # 滑动滚动条到某个指定的元素
        js4 = "arguments[0].scrollIntoView();"
        # 将下拉滑动条滑动到当前div区域
        driver.execute_script(js4, tag)

在调用ActionChains前,先调用一下这个函数,让窗口显示出你要处理的element,就不会报错了。

[selenium]selenium.common.exceptions.MoveTargetOutOfBoundsException的处理

原文:https://www.cnblogs.com/aocshallo1/p/12549653.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!