元素点击被截获硒中的错误

时间:2019-10-04 10:56:05

标签: angular selenium selenium-chromedriver

我遇到硒问题,正在测试角位。

在此屏幕上,我想按发布名称字段: enter image description here

如您所见,这是一个打开的侧边菜单, 这是HTML: enter image description here

我尝试等待元素被单击,然后它通过了。 这是我的代码:

public static void insertPublisherName(String publisherName)
    {
      //  BasePage.manuallyKeyboardPressing(Keys.ESCAPE);
      //  Logger.info("\n ******************* insert publisher name by Xpath: "+ COMPANY_NAME_XPATH +" *\n **************************************************\n");
      //  BasePage.inputValueByXpath(publisherName,COMPANY_NAME_XPATH);
        WebDriver driver2 = WebDriverMgr.getDriver();
        driver2.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
        WebDriverWait wait = new WebDriverWait(driver2,58);
        wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@formcontrolname='publisher_name']")));

        WebElement element = driver2.findElement(By.xpath("//input[@formcontrolname='publisher_name']"));
        element.click();
        element.clear();
        element.sendKeys("123465");


    }

这是一个例外:

:ERROR: element click intercepted: Element <input _ngcontent-xni-c24="" autocomplete="off" formcontrolname="publisher_name" nz-input="" placeholder="Enter Publisher Name" class="ant-input ng-untouched ng-pristine ng-valid" ng-reflect-name="publisher_name"> is not clickable at point (1560, 116). Other element would receive the click: <div class="ng-tns-c0-94 ant-notification-notice-with-icon">...</div>
  1. 我也尝试过按esc键来硒,但这仍然是错误, 我该如何克服这个问题?

  2. 我怎么知道在哪里单击该元素将可以自由单击我需要的位置 他点击 这不是等待的问题,因为当我进行调试时,我会等待更多次并仍然收到此错误

致谢

4 个答案:

答案 0 :(得分:0)

该异常消息表明某个特定元素位于目标的前面。在任何一个屏幕截图中我都没有看到,但是很明显它在测试运行时显示。
您应该在没有调试器的情况下观察运行情况,以查看是否弹出一个通知,拦截该自动点击,然后消失。

您可能需要等待通知并取消该通知,然后才能单击输入。

答案 1 :(得分:0)

由于以下情况而发生此问题:

  1. 浏览器大小/元素不在视口中
  2. 由于等待问题
  3. 一个弹出窗口/ alert出现在屏幕上

使用“浏览器大小”或“查看端口”使用以下选项:

browser.manage().window().setSize(1600, 1000);
browser.actions().mouseMove(element).click();
  

注意:如果上述方法也不起作用,请尝试链接perform()方法

browser.actions().mouseMove(element).click().perform();

要等待的问题:

browser.driver.sleep(3000)
  

注意:这不是放置或执行等待的标准方式

最好的方法是:

WebDriverWait wait = new WebDriverWait(driver,60);
        wait.until(ExpectedConditions.elementToBeClickable(By.xpath("xpath")));

对于弹出/警报:

处理窗口或警报,然后执行所需的操作

处理窗口:

browser.getAllWindowHandles().then(function(handles){
    var count=handles.length;
    var newWindow = handles[count-1];
    browser.switchTo().window(newWindow).then(function(){
        //do your stuff on the pop up window
    });
});

处理警报:

接受:

browser.driver.switchTo().alert().accept();

关闭:

browser.driver.switchTo().alert().dismiss();

答案 2 :(得分:0)

有时,您可以通过发送空格或输入条形码来避开被阻止的点击。试试:

element.sendKeys(Keys.SPACE);

element.sendKeys(Keys.ENTER);

但是,如果查看阻止点击的元素的类,则可能是一条通知,在这种情况下,您必须先关闭该通知。已经发布了一些解释该操作方法的答案。

答案 3 :(得分:0)

我最近遇到了类似的问题。我不使用Selenium进行测试,而是将其作为从项目的网站上检索数据的自动方式。在某些情况下,例如通过Task Scheduler运行时,在隐藏浏览器窗口且其几何最有可能导致隐藏元素问题的情况下运行时,我遇到了相同的“ ElementClickInterceptedError”错误。当我单击链接以打开另一个选项卡中的页面时,我总结了“单击”的概念,而是通过getAttributes(“ href”)检索链接,然后调用executeScript(“ window.open(),'target' );“)打开链接。然后,我切换到窗口并获取我的数据。自从我放弃点击以来,错误从未消失。