gpt4 book ai didi

python - 如何处理 wait.until 的超时异常

转载 作者:太空宇宙 更新时间:2023-11-03 12:08:31 25 4
gpt4 key购买 nike

wati.until 执行时获取超时异常。我不知道为什么会这样,因为在刷新网页时 img 元素不会显示给用户。

wait.until(EC.invisibility_of_element_located((By.XPATH,"//img[@src='//www.ibm.com/i/c.gif']")))


raise TimeoutException(message)
selenium.common.exceptions.TimeoutException: Message: ''

这是我的代码:

from selenium import webdriver    
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0
from selenium.webdriver.common.by import By
import selenium.webdriver.support.ui as ui

driver=webdriver.Firefox()
driver.get('https://www-01.ibm.com/products/hardware/configurator/americas/bhui/launchNI.wss')
driver.find_element_by_id("modelnumber").send_keys("7383AC1")
driver.find_element_by_name("submit").click()
element1 = driver.find_element_by_xpath("//label[contains(text(),'SLES for SAP Apps 8 Skt Virt Unlimited Subs Only 5Yr (5731SLX)')]")
id=element1.get_attribute('for')
driver.find_element_by_id(id).click()

#updated with wait until
wait.until(EC.invisibility_of_element_located((By.XPATH,"//img[@src='//www.ibm.com/i/c.gif']")))

最佳答案

通过修改如下代码解决了我的问题:

driver=webdriver.Firefox()
driver.get('https://www-01.ibm.com/products/hardware/configurator/americas/bhui/launchNI.wss')
driver.find_element_by_id("modelnumber").send_keys("7383AC1")
driver.find_element_by_name("submit").click()
element1 = driver.find_element_by_xpath("//label[contains(text(),'SLES for SAP Apps 8 Skt Virt Unlimited Subs Only 5Yr (5731SLX)')]")
id=element1.get_attribute('for')
driver.find_element_by_id(id).click()
print driver.title

wait=ui.WebDriverWait(driver,300)
image1=driver.find_element_by_xpath("//img[@src='//www.ibm.com/i/c.gif']")
print image1.get_attribute('class')
div1=driver.find_element_by_id("genMask_c")
wati.until(EC.staleness_of(driver.find_element_by_id("genMask_c")), 'visible')
driver.find_element_by_id("continueTop").click()
print driver.title

关于python - 如何处理 wait.until 的超时异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17598250/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com