Webdriver Selenium 单击 Iframe 内的 <li> 元素

Webdriver Selenium click a <li> element inside an Iframe

[![在此处输入图片描述][1]][1]尝试点击并 select 标记的

  • 元素.

    https://i.stack.imgur.com/cIRn8.png

    #选项 - https://i.stack.imgur.com/e66m1.png

    使用

    from selenium import webdriver
    from time import sleep
    from selenium.webdriver.support.ui import Select
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    

    当前尝试:

    driver.switch_to.frame(driver.find_element_by_id("moduleManagement")) driver.find_element_by_class_name("ranges").find_element_by_tag_name("ul").find_element_by_tag_name("li").click()

    我需要有关如何 select

  • 的帮助 元素 。我穿的地方

  • 我建议您对 switch to frame 使用 显式等待 并与他们互动 :

    点击第二个 li 标签,下面的代码应该适合你。

    wait = WebDriverWait(driver, 10)
    wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID, "moduleManagement")))
    wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div#colorbox+div[class^='daterangepicker']"))).click()
    second_li_element = wait.until(EC.visibility_of_element_located((By.XPATH, "(//li[@data-range-key])[2]")))
    second_li_element.click()
    

    进口:

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC