【问题标题】:Selenium Python selecting dropdown elementSelenium Python 选择下拉元素
【发布时间】:2021-04-28 02:00:50
【问题描述】:

我很难找到与 代码: 右侧的下拉框对应的 Web 元素。我尝试过使用 Select,通过 tag_name、css_selector、xpath、name、class_name、select_by_visible_text 查找,但无法获得。我猜问题是下拉框嵌套在表单标签中,在图片中以蓝色突出显示。我得到的最接近的是:

element = WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div#code_section_srch form#expertsearchformid select#expertsearchformid:toctextcodeid")))

你能帮我理解我做错了什么吗?

任何见解将不胜感激!

【问题讨论】:

    标签: python selenium css-selectors


    【解决方案1】:

    您必须使用配额、转义冒号或使用按 ID 查找:

    • div#code_section_srch form#expertsearchformid select#expertsearchformid\:toctextcodeid
    • div#code_section_srch form#expertsearchformid select[id='expertsearchformid:toctextcodeid']

    这应该可行:

    element = WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.ID, "expertsearchformid:toctextcodeid")))
    element = WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "[id='expertsearchformid:toctextcodeid']")))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-13
      • 1970-01-01
      • 1970-01-01
      • 2017-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多