Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Selenium在使用线程时既不隐式也不显式等待_Python_Multithreading_Selenium_Wait - Fatal编程技术网

Python Selenium在使用线程时既不隐式也不显式等待

Python Selenium在使用线程时既不隐式也不显式等待,python,multithreading,selenium,wait,Python,Multithreading,Selenium,Wait,我正在开发一个gui,它接受值并基于这些值运行Selenium测试。我决定将selenium作为线程运行,因为这会使gui无响应。唯一的问题是没有等待。好像等待根本就不存在。我假设它作为一个线程运行会阻止等待运行,因为我以前使用过等待,没有任何问题。我经常看到有人在这里要求代码,但实际上没有什么可以显示的 以下是我如何启动线程: def selenium_stuff(): ... t = threading.Thread(target=selenium_stuff) t.start()

我正在开发一个gui,它接受值并基于这些值运行Selenium测试。我决定将selenium作为线程运行,因为这会使gui无响应。唯一的问题是没有等待。好像等待根本就不存在。我假设它作为一个线程运行会阻止等待运行,因为我以前使用过等待,没有任何问题。我经常看到有人在这里要求代码,但实际上没有什么可以显示的

以下是我如何启动线程:

def selenium_stuff():
    ...

t = threading.Thread(target=selenium_stuff)
t.start()
这就是我所说的等待

self.driver.implicitly_wait(20)
所以我想我的问题是:作为线程运行的selenium测试是否不能等待?如果没有,最有可能出问题的是什么?提前感谢您的帮助

遗憾的是,我在Windows8上运行这个程序,使用chromedriver v2.14和Selenium v2.45.0以及Python 2.7.5

更新

下面是一个要运行的最小示例

from selenium import webdriver
import threading

def selenium_stuff():
    driver = webdriver.Chrome()
    driver.get('http://google.com')
    driver.implicitly_wait(20)
    search = driver.find_element_by_id("lst-ib")
    search.send_keys('help me')
    button = driver.find_element_by_id("tsf")
    button.click()

t = threading.Thread(target=selenium_stuff)
t.start()

一般来说,如果一个线程等待,其他线程将不受阻碍地运行。否则,您将使GUI无响应。如果没有看到更多的代码(理想情况下是我自己可以在Python中运行的最小完整示例),很难说这是否是问题所在。@Kevin感谢您的回答。虽然我在看到您的回复后添加了一个示例,但在屏幕上装了几天玻璃后,我也神奇地找到了解决方案。时间就是解决办法。