用python selenium选择hidden<li></li>

2024-05-05 18:46:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我有这么多html源代码:

<div class="timezone" id="js-timezone"> <span class="timezone__current">2:27 (GMT +2)</span> <ul class="timezone__list"> <li><a href="javascript:void(0);" onclick="set_timezone('+3');"><span>+3</span>Moscow, Riyadh</a></li> <li><a href="javascript:void(0);" onclick="set_timezone('+4');"><span>+4</span>Muscat</a> </li> </ul> </div>

当我移动coursor到span^{cl3}时,它是隐藏的$

print ('Opening browser...')
driver = webdriver.Firefox(executable_path = 'C:\geckodriver\geckodriver.exe')
driver.get("https://www.betexplorer.com/next/soccer/")
search_timezone = 
driver.find_element_by_xpath("//ul[@class='timezone__list']")
driver.execute_script('arguments[0].setAttribute("onclick", "set_timezone(+3);")', search_timezone)

什么都没发生。你知道吗

我也试过:

driver = webdriver.Firefox(executable_path = 'C:\geckodriver\geckodriver.exe')
driver.get("https://www.betexplorer.com/next/soccer/")
search_timezone = 
driver.find_element_by_xpath("//ul[@class='timezone__list']")
wait = WebDriverWait(driver, 10)
action = ActionChains(driver)
action.move_to_element(search_timezone).perform()
select_timezone = wait.until(EC.element_to_be_clickable((By.LINK_TEXT, "+3 Moscow, Riyadh")))
select_timezone.click()

还有时间例外

拜托,帮帮我,我快疯了


Tags: divsearchdriverlielementjavascriptullist
1条回答
网友
1楼 · 发布于 2024-05-05 18:46:27

找到这个:

search_timezone = driver.find_element_by_class_name("timezone")
action = ActionChains(driver)
action.move_to_element(search_timezone).perform()
wait = WebDriverWait(driver, 10)
select_timezone = search_timezone.find_elements_by_tag_name('a')[3]
select_timezone.click()

相关问题 更多 >