簡體   English   中英

Python Selenium _ 錯誤:selenium.common.exceptions.TimeoutException

[英]Python Selenium _ Error: selenium.common.exceptions.TimeoutException

我正在研究 Selenium 的工作原理。 有些元素已完全加載,但無法點擊。 這是案例的例子。 Selenium 需要一段時間才能完全加載。 按鈕仍然不可點擊。 我認為 Selenium 找不到該元素。 我該如何解決這個問題?

url

https://www.google.co.kr/

我試圖點擊的按鈕

<a class="gb_A" aria-label="Google 앱" href="https://www.google.co.kr/intl/ko/about/products" aria-expanded="false" role="button" tabindex="0"><svg class="gb_Se" focusable="false" viewBox="0 0 24 24"><path d="M6,8c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2zM12,20c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2zM6,20c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2zM6,14c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2zM12,14c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2zM16,6c0,1.1 0.9,2 2,2s2,-0.9 2,-2 -0.9,-2 -2,-2 -2,0.9 -2,2zM12,8c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2zM18,14c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2zM18,20c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2z"></path></svg></a>

我的代碼

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome()
driver.get("https://www.google.co.kr/")
time.sleep(3)
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='gbwa']/div/a/svg/path"))).click()

錯誤信息

Traceback (most recent call last):
  File "C:\project\selenium test2.py", line 11, in <module>
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='gbwa']/div/a/svg/path"))).click()
  File "C:\project\venv\lib\site-packages\selenium\webdriver\support\wait.py", line 89, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: 
wait=WebDriverWait(driver,20)
driver.get("https://www.google.co.kr/")
wait.until(EC.element_to_be_clickable((By.XPATH, "//a[@class='gb_A']/*[local-name()='svg']/*[local-name()='path']"))).click()

現在似乎可以正常工作了,只需將其用於完成問題即可。 xpath 標識存在問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM