浏览器是FireFox,语言是Python。我无法完成CloudFlare人工验证。
在这个网站(https://chat.openai.com/chat https://chat.openai.com/chat),我无法通过以下代码找到“mark”元素:
verify=WebDriverWait(driver, 10,0.1).until(EC.presence_of_element_located((By.CLASS_NAME, 'mark')))
HTML:
错误信息:
Traceback (most recent call last):
File ,
verify=WebDriverWait(driver, 10,0.1).until(EC.presence_of_element_located((By.CLASS_NAME, 'mark')))
File "...Python310\lib\site-packages\selenium\webdriver\support\wait.py", line 90, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
Stacktrace:
RemoteError@chrome://remote/content/shared/RemoteError.jsm:12:1
WebDriverError@chrome://remote/content/shared/webdriver/Errors.jsm:192:5
NoSuchElementError@chrome://remote/content/shared/webdriver/Errors.jsm:404:5
element.find/</<@chrome://remote/content/marionette/element.js:291:16
为什么以及如何解决它。
元素<span class="mark>...</mark>
里面有可见的文字。所以要识别元素而不是元素存在位置() https://stackoverflow.com/a/57313803/7429447你需要诱导WebDriver等待 https://stackoverflow.com/a/59130336/7429447为了元素可见性() https://stackoverflow.com/a/50474905/7429447您可以使用以下任一方法定位策略 https://stackoverflow.com/a/48056120/7429447:
-
Using CSS_选择器:
element = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "label.ctp-checkbox-label span.mark")))
-
Using XPATH:
element = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//label[@class='ctp-checkbox-label']//span[@class='mark']")))
-
Note:您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)