开发者社区> 问答> 正文

使用python selenium选择隐藏的<li> </ li>

我有源代码html代码:


2:27 (GMT +2)
<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>



它是隐藏的,当我移动光标到span class =“timezone__current”显示菜单时。现在我试图用Python和Selenium点击“+3 GMT”

print ('Opening browser...')
driver = webdriver.Firefox(executable_path = 'C:geckodrivergeckodriver.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:geckodrivergeckodriver.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()
还有TimeoutException

展开
收起
一码平川MACHEL 2019-01-22 10:42:25 4709 0
2 条回答
写回答
取消 提交回答
  • selenium是基于事件级的。遮挡不怕不怕

    2019-11-22 14:02:10
    赞同 展开评论 打赏
  • 发现这个:

    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()

    2019-07-17 23:26:09
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
From Python Scikit-Learn to Sc 立即下载
Data Pre-Processing in Python: 立即下载
双剑合璧-Python和大数据计算平台的结合 立即下载