Selenium Python:如何set_page_load_timeout,如果超过时间返回except(不是错误)



我有这个代码和如何循环如果加载超时,它将返回除非它运行下一个测试用例

def search_action(self, xpath, value):
try:
self.driver.set_page_load_timeout(1)
element = self.driver.find_element(By.XPATH, xpath)
element.send_keys(value)
element.send_keys(Keys.ENTER)
except TimeoutException as e:
print('EXCEPT', e)
pass
print('success')

se = class_name()

for domain in config['list_domain']:
se.get_domain(domain)
for i in range(1, 100):
xpath = config[domain]['list_test']['search']
se.search_action(xpath, i)
se.get_domain(domain)

返回:

selenium.common.exceptions.TimeoutException: Message: timeout: Timed out receiving message from renderer: 0.319

我想从1到100循环,我不想返回错误

我猜你的问题不是与set_page_load_timeout
你需要使用WebDriverWaitexpected_conditions等待元素成为可点击的。

wait.until(EC.element_to_be_clickable((By.XPATH, xpath)))

因为你没有分享链接和xpath的细节,所以我不能在这里给出更详细的答案。

最新更新