【问题标题】:Select RadioButton Selenium python选择 RadioButton Selenium python
【发布时间】:2020-01-17 23:18:07
【问题描述】:

在网站上:https://www.investing.com/economic-calendar/ 我尝试设置一些过滤器来收集数据。我想将过滤时间设置为:“仅显示时间”和过滤器重要性:2 和 3 牛。我尝试了以下脚本,但没有一个单选按钮是可交互的。

base_url = "https://www.investing.com/economic-calendar/"
driver = webdriver.Chrome(path, port=5007)
driver.get(base_url)

# expand filters
driver.find_element_by_id("filterStateAnchor").click()

Radio_bull2 = driver.find_element_by_xpath("//input[@id='importance2']")
Radio_bull2.click()

Radio_bull3 = driver.find_element_by_xpath("//input[@id='importance3']")
Radio_bull3.click()

Radio_time = driver.find_element_by_xpath("//input[@id='timetimeOnly']")
Radio_time.click()

我将非常感谢您对此的帮助。谢谢!

【问题讨论】:

    标签: python selenium selenium-webdriver


    【解决方案1】:

    点击动态元素如Display time only和bull2 & bull3诱导WebDriverWait和element_to_be_clickable()

    WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.ID,'filterStateAnchor'))).click()
    WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.ID,'timetimeOnly'))).click()
    WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.ID,'importance2'))).click()
    WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.ID,'importance3'))).click()
    

    您需要添加以下库。

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

    【讨论】:

      猜你喜欢
      • 2016-07-18
      • 1970-01-01
      • 2017-03-12
      • 1970-01-01
      • 2014-03-23
      • 2017-11-02
      • 1970-01-01
      • 1970-01-01
      • 2023-03-29
      相关资源
      最近更新 更多