【问题标题】:Element is not clickable at point - other element would receive the click元素此时不可点击 - 其他元素将收到点击
【发布时间】:2018-10-26 03:20:57
【问题描述】:

我在网站上有一个元素,如下所示

        <div id="wrapperCategory" class="categoryItemWrapper">
        <div class="panel panel-default panel-categoryItem text-center categoryItem disabledItem" ng-class="category.CategoryStyleClass" ng-click="setselectedProduct(productIndex,product,category); setselectedProductAmount(null);" title="Category">
            <div class="panel-heading">
                Category
            </div>
            <div class="panel-body">
                Price
            </div>
            <div class="panel-footer availability" ng-class="category.AvailabilityStyleClass">
                <span ng-bind-html="category.AvailabilityText">Avail</span>
            </div>
        </div>
    </div>

我需要点击它才能前进。如果我手动单击每个这些 div 或跨网站继续前进,但 SeleniumWebdriver 无法单击其中任何一个。 每次出现错误时,我都尝试使用 ng-click 事件单击 span 和 div:

Exception in thread "main" org.openqa.selenium.WebDriverException: Element <div class="panel panel-default panel-categoryItem text-center categoryItem" ng-class="category.CategoryStyleClass" ng-click="setselectedProduct(productIndex,product,category); setselectedProductAmount(null);" title="Category"></div> is not clickable at point (619.2666625976562, 474.23333740234375). Other element would receive the click: <div style="top: 0;left: 0;bottom: 0;right: 0;position: fixed;pointer-events: auto !important;z-index: 10000;" id="cover-1526454140024"></div>

我不明白。 我可以以某种方式检查哪个元素是可点击的,哪个元素与我想要点击的元素重叠(我在网站的代码中没有看到任何 id="cover-1526454140024" 的 div)?

更新: 不幸的是,在您的解决方案之后它仍然不起作用。 尝试点击时出现同样的异常。

//    try {
//      Thread.sleep(1000);
//    } catch (InterruptedException e) {
//      e.printStackTrace();
//    }
    JavascriptExecutor js = (JavascriptExecutor) Mundial.driver;
    js.executeScript("arguments[0].scrollIntoView();", categoryItem);

    new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(categoryItem));
    categoryItem.click();
    List<WebElement> selects = driver.findElements(By.tagName("select"));
    Select ticketsToSelect = new Select(selects.get(3));
    ticketsToSelect.selectByValue("number:2");

它仅在我进入睡眠状态并手动向下滚动时才有效。没看懂。

【问题讨论】:

  • 尝试在点击事件前添加等待
  • 当你的脚本正在运行并且你正在可视化时,你能看到元素并且仍然得到错误吗?或者您是否必须向下滚动或执行某些操作才能查看元素交互。
  • 添加您的代码试验,这会很有帮助
  • @cruisepandey 这就是解决方案。我没有看到这个元素,需要向下滚动然后它才能工作。谢谢:)

标签: java selenium webdriver


【解决方案1】:

根据您的回复:

您必须向下滚动才能让网络元素可用于您的脚本。为此,您可以使用以下代码:

public static void scrollDown(WebDriver driver, String YoffSet){
            JavascriptExecutor jse = (JavascriptExecutor)driver;
            jse.executeScript(YoffSet);
    }

在这里,您可以在代码中的任何位置调用此方法。

然后您可以使用此代码与 web 元素进行交互:

WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("static ID")));  
element.click();

【讨论】:

  • 不幸的是,如果我不手动滚动,它就不起作用。我用我的代码更新了第一篇文章。可以看看吗?
  • @kris82pl : 向下滚动有多种方式,我会在评论区一一贴出代码。
  • JavascriptExecutor jse = (JavascriptExecutor)驱动程序; jse.executeScript("window.scrollBy(0,500)", "");
  • Actions action = new Actions(driver); action.sendKeys(Keys.PAGE_DOWN).build().perform();
  • 您可以根据需要多次调用 sendKeys(Keys.PAGE_DOWN)。像这样:action.sendKeys(Keys.PAGE_DOWN).sendKeys(Keys.PAGE_DOWN).build().perform();
【解决方案2】:

我遇到过很多这样的问题,正如 Ankur 所说,使用点击前等待

WebElement seems_unclickable = wait.until(ExpectedConditions.elementToBeClickable(By.id(...

【讨论】:

    【解决方案3】:

    其中一种方法是 ExpectedConditions 命令

    WebDriverWait wait = new WebDriverWait(driver, 10);
    WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("Yourid")));
    

    更多示例可以在http://toolsqa.com/selenium-webdriver/wait-commands/找到

    【讨论】:

      【解决方案4】:

      试试“scrollIntoView”。

      public void ScrollElementIntoView(IWebElement element)
          {
              var js = driver as IJavaScriptExecutor;
              js.ExecuteScript("arguments[0].scrollIntoView()", element);
          }
      

      【讨论】:

        【解决方案5】:

        我遇到了同样的问题,这是由于对页面正文应用了非 100% 缩放,例如:

        body {
          zoom: 90%;
        }
        

        移除 css 缩放解决了这个问题。

        【讨论】:

          猜你喜欢
          • 2016-12-19
          • 2016-06-08
          • 2018-03-16
          • 2017-04-16
          • 2017-11-27
          相关资源
          最近更新 更多