开发者社区> 问答> 正文

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

一码平川MACHEL 2019-01-22 10:42:25 1049

我有源代码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

JavaScript 前端开发 Python
分享到
取消 提交回答
全部回答(1)
  • 一码平川MACHEL
    2019-07-17 23:26:09

    发现这个:

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

    0 0

集结各类场景实战经验,助你开发运维畅行无忧

推荐文章
相似问题
推荐课程