我正在实现一个脚本,使用Selenium Webdriver和Python对一些网页进行爬网,但是我有一个特殊的问题。在某个时刻,我应该获取一个input元素并发送一个key,在我的本地PC上脚本运行得很好,而在我的服务器上,这个元素的结果是不可见的。 页面的HTML部分是:
<div class="class1" style="width: 309px;">
<div class="sPb-a">
<div class="class2" style="display: none;" aria-hidden="true">
www.lol.com
</div>
<input class="class3" type="text" dir="ltr" style="width: 301px;"></input>
</div>
<div></div>
</div>
在Python中,这是我的代码:
^{pr2}$但当我对元素调用clear方法时,脚本捕捉到以下错误:
Element is not currently visible and so may not be interacted with
Stacktrace:
at fxdriver.preconditions.visible (file:///tmp/tmpma637_/extensions/fxdriver@googlecode.com/components/command-processor.js:9982)
at DelayedCommand.prototype.checkPreconditions_ (file:///tmp/tmpma637_/extensions/fxdriver@googlecode.com/components/command-processor.js:12626)
at DelayedCommand.prototype.executeInternal_/h (file:///tmp/tmpma637_/extensions/fxdriver@googlecode.com/components/command-processor.js:12643)
at DelayedCommand.prototype.executeInternal_ (file:///tmp/tmpma637_/extensions/fxdriver@googlecode.com/components/command-processor.js:12648)
at DelayedCommand.prototype.execute/< (file:///tmp/tmpma637_/extensions/fxdriver@googlecode.com/components/command-processor.js:12590)
我还要补充说两个信息:
你知道有什么解决办法吗? 非常感谢
我能想到一些值得检查的东西。您可能需要等待一段时间才能加载页面。我在测试中遇到了一些服务器延迟问题,导致一些东西失败,所以值得检查一下。在
人们倾向于遇到的另一件事是地址here。有时,当某个元素在浏览器窗口中不可见时,Web驱动程序将无法找到它。这里有一些用于滚动浏览器窗口的代码片段(它们是用Java编写的链接,但是转换到Python应该相当简单)。只需在使用
find_element_by_xpath()
之前删除该代码,这样就可以处理它了。祝你好运!在相关问题 更多 >
编程相关推荐