gpt4 book ai didi

python - CSS 选择器在 Selenium 脚本中抛出超时异常

转载 作者:太空宇宙 更新时间:2023-11-03 21:19:01 26 4
gpt4 key购买 nike

Traceback (most recent call last):File "C:\Users\PSWN672P\AppData\Local\Programs\Python\Python37\Python programs\SNOW1.py", line 17, in EC.element_to_be_clickable((By.CSS_SELECTOR,'ul[id*="collapseId"]>li:nth-child(5)>ul[id*="collapseId"]>li>div>a>div>div')) File "C:\Users\PSWN672P\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:

尝试访问文本为My Groups Work的元素并运行脚本以自动单击该元素并导航到下一页:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support import expected_conditions as EC
import time


browser=webdriver.Ie()
browser.get('http://example.com')

try:

window_before=browser.window_handles[0]
element=WebDriverWait(browser,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,'ul[id*="collapseId"]>li:nth-child(5)>ul[id*="collapseId"]>li>div>a>div>div')))
element.click()
time.sleep(15)
window_after=browser.window_handles[1]
browser.switch_to_window(window_after)

finally:

browser.quit()

<a class="sn-widget-list-item sn-widget-list-item_hidden-action module-node" id="2ccb50dfc61122820032728dcea648fe" href="task_list.do?sysparm_userpref_module=2ccb50dfc61122820032728dcea648fe&amp;sysparm_query=assignment_group=javascript:getMyGroups()^active=true^assigned_to=^sys_class_name!=cert_follow_on_task^sys_class_name!=sc_req_item^sys_class_name!=sc_request^EQ&amp;sysparm_clear_stack=true" target="gsft_main"><div class="sn-widget-list-content" data-id="2ccb50dfc61122820032728dcea648fe">
<div class="sn-widget-list-content" data-id="2ccb50dfc61122820032728dcea648fe">
<div class="sn-widget-list-title">My Groups Work</div>
</div>
</a>

最佳答案

为什么不直接通过类名来定位元素?

element=WebDriverWait(browser,10).until(EC.element_to_be_clickable((By.CLASS_NAME,'sn-widget-list-title')))

关于python - CSS 选择器在 Selenium 脚本中抛出超时异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54452308/

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