代码之家  ›  专栏  ›  技术社区  ›  Erin

选择下拉元素

  •  0
  • Erin  · 技术社区  · 5 年前

    我很难找到与直接位于页面右侧的下拉框对应的web元素 代码: . 我试过使用Select,finding by tag\u name,css\u selector,xpath,name,class\u name,Select\u by \u visible\u text,但都没有得到它。我猜问题是下拉框嵌套在表单标签中,在图片中以蓝色突出显示。我得到的最接近的结果是:

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

    enter image description here

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

    任何洞察都将不胜感激!

    1 回复  |  直到 5 年前
        1
  •  0
  •   Sers    5 年前

    必须使用配额、转义冒号或按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']")))