亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 python 中的 Selenium 中使用顯式等待時總是出現 TimeoutException

在 python 中的 Selenium 中使用顯式等待時總是出現 TimeoutException

慕后森 2022-10-11 21:22:48
我有下面的代碼。from selenium import  webdriverimport timefrom selenium.webdriver.support.ui import Selectfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as ECfrom selenium.webdriver.common.by import Bydriver = webdriver.Chrome() #driver.implicitly_wait(10) #https://blog.csdn.net/u010895119/article/details/77005886driver.get('http://www.aim.env.uea.ac.uk/aim/model4/model4d.php') #button = driver.find_element_by_id('add_organic')#button.click()#input = driver.find_element_by_id("selection_box_id")#input.click()driver.find_element_by_xpath('//*[@id="selection_box_id"]/option[3]').click() #driver.find_element_by_xpath('//*[@id="selection_box_div"]/p/input').click()#input = driver.find_element_by_id("selection_box_id")#input.click()driver.find_element_by_xpath('//*[@id="selection_box_id"]/option[7]').click()#driver.find_element_by_xpath('//*[@id="selection_box_div"]/p/input').click()# driver.find_element_by_xpath('//*[@id="BacktoCalculation_id"]').click() ##driver.execute_script("window.history.go(-1)") #https://stackoverflow.com/questions/27626783/python-selenium-browser-driver-backwait = WebDriverWait(driver, 10) # element = wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="mainForm"]/div[2]/table/tbody/|tr/td[3]/input')))# element.click()我總是遇到超時錯誤:raise TimeoutException(message, screen, stacktrace)selenium.common.exceptions.TimeoutException: Message:但是當我嘗試直接找到元素時,它確實有效。但我需要在這里明確等待以確保安全。任何人都可以幫助找出上面代碼中的問題嗎?非常感謝!element = driver.find_element_by_xpath('//*[@id="mainForm"]/div[2]/table/tbody/tr/td[3]/input')
查看完整描述

1 回答

?
慕桂英3389331

TA貢獻2036條經驗 獲得超8個贊

這是因為您的 xpath 中有錯字


'//*[@id="mainForm"]/div[2]/table/tbody/|tr/td[3]/input' # error

'//*[@id="mainForm"]/div[2]/table/tbody/tr/td[3]/input'  # ok

這工作正常


wait = WebDriverWait(driver, 10) #

element = wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="mainForm"]/div[2]/table/tbody/tr/td[3]/input')))#

element.click()


查看完整回答
反對 回復 2022-10-11
  • 1 回答
  • 0 關注
  • 196 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號