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

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

我在使用 Python Selenium 時遇到網頁加載時間錯誤

我在使用 Python Selenium 時遇到網頁加載時間錯誤

www說 2023-12-11 16:01:28
# Path to the chromedriver programservice = Service('C:\Program Files (x86)\Google\chromedriver.exe')service.start()# Driver opens the remote with robinhood websitedriver = webdriver.Remote(service.service_url)driver.get('https://robinhood.com/crypto/BTC')# We will grab the element id's to log on to Robinhood# driver.find_element_by_id(“ID”).send_keys(“username”)# driver.find_element_by_id (“ID”).send_keys(“password”)# driver.find_element_by_id(“submit”).click()signinButton = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CLASS_NAME, "_3kh8OsNx6QdAbMaoKTi2Yq _1uaripz9PIQ8yApSTs6BKk")))# driver.find_element_by_class_name('_3kh8OsNx6QdAbMaoKTi2Yq _1uaripz9PIQ8yApSTs6BKk')signinButton.click()# Closes the driver after timeoutdriver.quit()我基本上是打開 chrome webdriver 并訪問 robinhood 網站,但是我遇到了網頁加載問題。為了修復它,我嘗試使用 WebDriverWait 停止按鈕單擊,直到加載網頁。問題是按鈕單擊在 10 秒過去后不會執行,而是拋出此錯誤:Traceback (most recent call last):  File "D:/gitRepos/bitmine/runmine.py", line 25, in <module>    signinButton = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CLASS_NAME, "_3kh8OsNx6QdAbMaoKTi2Yq _1uaripz9PIQ8yApSTs6BKk")))  File "D:\Programs Files 2\Python\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until    raise TimeoutException(message, screen, stacktrace)selenium.common.exceptions.TimeoutException: Message: 
查看完整描述

4 回答

?
阿波羅的戰車

TA貢獻1862條經驗 獲得超6個贊

此錯誤是由于同步問題而發生的。Yu可以通過使用selenium中的等待來解決您的問題。請參考以下解決方案以避免此類錯誤:


WebDriverWait(driver, 30).until(

                EC.element_to_be_clickable((By.XPATH, "//button[@class='_3kh8OsNx6QdAbMaoKTi2Yq _1uaripz9PIQ8yApSTs6BKk']"))).click()

注意:請將以下導入添加到您的解決方案中


from selenium.webdriver.support import expected_conditions as EC

from selenium.webdriver.common.by import By

from selenium.webdriver.support.ui import WebDriverWait

免費注冊按鈕部分:


wait.until(EC.element_to_be_clickable((By.XPATH, "//button[@class='_3kh8OsNx6QdAbMaoKTi2Yq _1uaripz9PIQ8yApSTs6BKk']"))).click()


wait.until(EC.element_to_be_clickable((By.XPATH, "//span[contains(text(),'Sign up for free')]"))).click()



查看完整回答
反對 回復 2023-12-11
?
海綿寶寶撒

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

該錯誤意味著它在 10 秒內沒有找到可點擊的按鈕,并且超時,拋出 TimeoutException。需要設置更長的等待時間,或者相應處理TimeoutException



查看完整回答
反對 回復 2023-12-11
?
繁花不似錦

TA貢獻1851條經驗 獲得超4個贊

該錯誤通常是由于無法在定義的時間段內找到該對象而引發的。我寧愿你設置一個異常錯誤來捕獲它,并在失敗時繼續查找下一個對象或元素。


try:

    #Insert your scraping action here

    signinButton.click()

except NoSuchElementException:


查看完整回答
反對 回復 2023-12-11
?
Helenr

TA貢獻1780條經驗 獲得超4個贊

該錯誤意味著 selenium 無法在指定的時間內找到該元素。


也不要在類名中使用空格。只需使用點.,否則無論您增加時間,硒都將無法找到它。


from selenium import webdriver


driver = webdriver.Firefox()


driver.get("https://robinhood.com/crypto/BTC")


element = driver.find_element_by_class_name(

    "_3kh8OsNx6QdAbMaoKTi2Yq._1uaripz9PIQ8yApSTs6BKk")


print(element)


查看完整回答
反對 回復 2023-12-11
  • 4 回答
  • 0 關注
  • 184 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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