Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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 硒工作在';TimeoutException';没有定义吗?_Python_Selenium - Fatal编程技术网

Python 硒工作在';TimeoutException';没有定义吗?

Python 硒工作在';TimeoutException';没有定义吗?,python,selenium,Python,Selenium,我想解决Python Selenium中的TimeOutException问题。 发生这种情况: 1.) Open Browser, Call URL 2.) Trying to find Element 2.1) Works sometimes 2.2) Works not sometimes and throws TimeoutException 3.) Should look for other elements 在我们在2.2)中遇到异常后,我永远无法到达步骤3.),和try/catc

我想解决Python Selenium中的TimeOutException问题。

发生这种情况:

1.) Open Browser, Call URL
2.) Trying to find Element
2.1) Works sometimes
2.2) Works not sometimes and throws TimeoutException
3.) Should look for other elements
在我们在
2.2)中遇到异常后,我永远无法到达步骤
3.)
和try/catch不起作用

在步骤
3.)之后。
还有许多其他步骤。我怎样才能让程序绕过这个超时。当元素不存在时,这就是时间旅行

代码

def getByClass(InputElement,驱动程序):
getByClass=WebDriverWait(驱动程序,超时)。直到(位于的元素的可见性)(By.CLASS\u名称,InputElement)))
返回getByClass
尝试:
element=Dom.getByClass('test-class',driver.).text
除TimeoutException外:
元素='未找到元素'
打印(元素)
结果

除TimeoutException外:
NameError:未定义名称“TimeoutException”

我看不到您的示例中的导入语句,因此请确保您有

来自selenium.common.exceptions的
导入TimeoutException

在您的
.py
文件的顶部。

我看不到您的示例中的导入语句,因此请确保

来自selenium.common.exceptions的
导入TimeoutException

.py
文件的顶部。

从selenium异常导入
TimeoutException
,如下所示:

来自selenium.common.exceptions的
导入TimeoutException
将函数放入try块本身:

试试看:
getByClass=WebDriverWait(驱动程序,超时)。直到(位于的元素的可见性)(By.CLASS\u名称,InputElement)))
element=Dom.getByClass('test-class',driver.).text
除TimeoutException外:
元素='未找到元素'
打印(元素)

从selenium异常导入
TimeoutException
,如下所示:

来自selenium.common.exceptions的
导入TimeoutException
将函数放入try块本身:

试试看:
getByClass=WebDriverWait(驱动程序,超时)。直到(位于的元素的可见性)(By.CLASS\u名称,InputElement)))
element=Dom.getByClass('test-class',driver.).text
除TimeoutException外:
元素='未找到元素'
打印(元素)

在此处添加代码。我现在添加了代码。在此处添加代码。我现在添加了代码。如果您在某个范围内,一个提示是调用生成器。因此,你可以重新开始,而不要停止你正在进行的项目。如果你在某个范围内,有一个建议是调用一个生成器。所以你可以重新开始,不要停止你正在进行的项目。