【问题标题】:org.openqa.selenium.WebDriverException: unknown error: Element is not clickableorg.openqa.selenium.WebDriverException:未知错误:元素不可点击
【发布时间】:2015-03-18 12:27:53
【问题描述】:

我使用 selenium webdrive 在下拉列表中选择一个项目。

我要点击"game club"元素

我尝试了几个元素,但我收到一个错误,指出它们都不可点击。

org.openqa.selenium.WebDriverException: unknown error: Element is not clickable at point (790, 227). Other element would receive the click: <div id="select2-drop-mask" class="select2-drop-mask" style=""></div>
(Session info: chrome=41.0.2272.3)

但是,使用浏览器我肯定会点击该项目。

我怎样才能点击这个项目?

【问题讨论】:

标签: javascript html selenium jquery-selectors html.dropdownlistfor


【解决方案1】:

如果这是一个静态列表,我会使用SelectElement(IWebElement element) 方法。

C# 示例:

  var dropDown = _webDriver.FindElement(By.ClassName("select2-result-sub"));
  var dropDownSelector = new SelectElement(dropDown);
  dropDownSelector.SelectByIndex(3);

【讨论】:

    【解决方案2】:

    你可以试试:

    public void click( By element ) {
        WebElement button = driver.findElement( element );
        try {
            button.click();
        } catch ( WebDriverException e ) {
            List<WebElement> availables = button.findElements( By.tagName( "div" ) );
            availables.addAll( button.findElements( By.tagName( "span" ) ) );
            tryClick( availables );
        }
    }
    
    public void tryClick( List<WebElement> availables ) {
        for ( WebElement candidate : availables ) {
            try {
                candidate.click();
                return;
            } catch ( WebDriverException e ) {
                continue;
            }
        }
    }
    

    之后使用(例如):

    click(By.id("elementId"));
    

    问候!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-14
      • 1970-01-01
      • 1970-01-01
      • 2016-12-29
      • 2018-03-16
      • 2012-08-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多