【问题标题】:Element at "//div[contains(@class,"connexion-content")]//select" is not clickable"//div[contains(@class,"connexion-content")]//select" 处的元素不可点击
【发布时间】:2021-04-30 11:29:29
【问题描述】:

我正在尝试在 Web 应用程序(Angular2、https 和 websocket)上运行一些测试自动化:gherkin、behave 1.2.6、selenium 3.141.0、firefox 和 python 3.9.4、geckodriver 0.29.1、allure -表现 2.8.40。

配置: user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:87.0) Gecko/20100101 Firefox/87.0"

定位器: select = (By.XPATH, '//div[contains(@class,"connexion-content")]//select')

错误: 断言失败:在当前页面中找不到项目“profilselect.select”,无法在其上设置值 捕获的日志记录:WARNING:root:[ACTION] waitForClickable => "//div[contains(@class,"connexion-content")]//select" 处的元素不可点击。

我要选择的 HTML 选项:请注意不能使用 «值»,因为我只对«选项»标签之间的文本感兴趣,只有当给定文本对应于它的特定值时被选中

【问题讨论】:

    标签: python-3.x selenium-webdriver firefox geckodriver python-behave


    【解决方案1】:

    既然你的元素本身是 select 类型,为什么不使用 Selenium Select 类,你可以通过文本或索引直接与它交互。

    【讨论】:

    【解决方案2】:

    由于您没有显示您的代码,我只能提供伪代码:

    we_sel = WebDriverWait(driver, 10).until(expected_conditions.visibility_of_element_located((By.ID, 'form-1-1'))
    
    # The above statement is equivalent to below statement.
    
    # If you are not familiar with WebDriver Waits then uncomment the below statement and comment the above statement.
    
    # we_sel = driver.find_element_by_id('form-1-1')
    
    sel = Select(we_sel)
    sel.select_by_visible_text('replace withoption text u want to select')
    

    参考资料(Webdriver API 文档):

    1. 对于Select 类: https://www.selenium.dev/selenium/docs/api/py/webdriver_support/selenium.webdriver.support.select.html#module-selenium.webdriver.support.select

    2. 对于WebDriverWait 类: https://www.selenium.dev/selenium/docs/api/py/webdriver_support/selenium.webdriver.support.wait.html#module-selenium.webdriver.support.wait

    3. 对于expected_conditions 模块: https://www.selenium.dev/selenium/docs/api/py/webdriver_support/selenium.webdriver.support.expected_conditions.html#module-selenium.webdriver.support.expected_conditions

    【讨论】:

      猜你喜欢
      • 2020-11-02
      • 2021-08-03
      • 2021-05-03
      • 2015-01-12
      • 1970-01-01
      • 2016-09-03
      • 2016-10-02
      • 1970-01-01
      • 2013-06-14
      相关资源
      最近更新 更多