如何使用适用于 IE 和 Python 的 Selenium WebDriver 查找过滤器按钮的元素:

How to find the element for the filter button using Selenium WebDriver for IE and Python:

我刚接触 Whosebug 和一般编程。

我正在使用 Selenium 使我公司的计费系统(仅适用于 IE)自动化,我需要按“过滤器”按钮才能在页面上显示我们的数据库所说的内容。为了找到元素,我尝试了 xpath 的多种变体,但似乎没有任何效果。这是过滤器按钮的 HTML 行:

<input style="background:green;color:white;" type=button class=bttn onclick="form1.formfilter.value='1';form1.submit();" value="FILTER">

有没有办法通过value="FILTER"找到这个元素?

我已经阅读了文档并寻找了这个答案,但我没有找到它,或者我没有搜索正确的关键字。

要使用属性 value="FILTER" 单击 FILTER 按钮,您必须诱导 for the element_to_be_clickable() and you can use either of the following :

  • 使用CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.bttn[value='FILTER']"))).click()
    
  • 使用XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='bttn' and @value='FILTER']"))).click()
    
  • 注意:您必须添加以下导入:

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