Python Selenium driver.implicitly_wait(30) [英] Python Selenium driver.implicitly_wait(30)

查看:1407
本文介绍了Python Selenium driver.implicitly_wait(30)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用VM进行开发,并使用Jenkins作为套件.今天早上,我们遇到了从未发生过的硒测试问题.在粘贴代码之前,重要的是要知道硒测试可以在我的机器上运行,但不能在Jenkins上运行.(而且已经运行了一个月)

We are using VM for the development and Jenkins as a suite. this morning we had a problem with a Selenium test that never happened before. Before I paste the code, it's important to know that the selenium test works on my machine but fails on Jenkins.. (And that it has been working for month)

class Remote(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Firefox()
        self.driver.implicitly_wait(30)
        self.base_url = "https://developer.intuit.com/"
        self.verificationErrors = []
        self.accept_next_alert = True

这是导致此错误的代码:

Here is the code that is causing this bug :

ERROR: test_sl_front (__main__.SlFront)

Traceback (most recent call last):
  File "./scripts/test-sl/sl-front.py", line 160, in setUp
    self.driver.implicitly_wait(30)
  File "/var/lib/jenkins/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 778, in implicitly_wait
    'implicit': int(float(time_to_wait) * 1000)})
  File "/var/lib/jenkins/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 308, in execute
    self.error_handler.check_response(response)
  File "/var/lib/jenkins/.local/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
    raise exception_class(message, screen, stacktrace)
WebDriverException: Message: timeouts

这很奇怪,因为昨天和前一天一切正常. 我试图删除".Firefox()",以为它可能与问题有关,但是没有任何变化.

It is very weird since everything worked fine yesterday and the day before that. I tried to remove the ".Firefox()" thinking it might be related to the problem but nothing changed.

问题是由使用了几个月的"self.driver.implicitly_wait(30)"引起的. 在詹金(Jenkin)的构建过程中,我们使用以下命令行启动此测试.

The problem is caused by "self.driver.implicitly_wait(30)" which has been used for months. We are using the following command line to start this test during the Jenkin's build.

export DISPLAY=:99
python ./scripts/test-sl/sl-front.py

推荐答案

我在将webdriver.Firefox()driver.implicitly_wait(IMPLICIT_WAIT)结合使用时遇到了相同的问题,并通过安装了新版本的geckodriver版本0.19.0解决了该问题(我的版本来自2017年6月之前.)

I had the same problem using webdriver.Firefox() with driver.implicitly_wait(IMPLICIT_WAIT) and solved it by installing a new version of geckodriver Version 0.19.0 (I had a version from June 2017 before).

从此处下载geckodriver: https://github.com/mozilla/geckodriver/releases.

Download geckodriver from here: https://github.com/mozilla/geckodriver/releases.

我的配置:

  • Firefox 56.0
  • 硒版本:3.4.3

在shell中检查geckodriver的版本:

Check the version of geckodriver in shell:

$ geckodriver -V
geckodriver 0.19.0

默认情况下,硒将使用您路径中的Firefox版本.要更改为其他版本,请使用:

By default selenium will use the firefox version that's in your path. To change to another version use:

from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

binary = FirefoxBinary(firefox_path='your firefox path', log_file='your logfile path')
driver = webdriver.Firefox(firefox_binary=binary)

硒网络驱动程序的文档

这篇关于Python Selenium driver.implicitly_wait(30)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆