org.openqa.selenium.ElementClickInterceptedException:在无头模式下使用Selenium和Java元素单击被拦截的错误 [英] org.openqa.selenium.ElementClickInterceptedException: element click intercepted error using Selenium and Java in headless mode

查看:147
本文介绍了org.openqa.selenium.ElementClickInterceptedException:在无头模式下使用Selenium和Java元素单击被拦截的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正在使用Java和Selenium的项目.在UI模式下测试工作正常.但是在无头模式下,我会收到此错误

I have a project that I am working on with java and selenium. the test work OK in UI mode. However in headless mode I get this error

org.openqa.selenium.ElementClickInterceptedException: element click intercepted: Element <label _ngcontent-yrc-c26="" formcontrolname="reportingDealPermission" nz-checkbox="" class="ant-checkbox-wrapper ng-untouched ng-pristine ng-valid" ng-reflect-name="reportingDealPermission">...</label> is not clickable at point (161, 562). Other element would receive the click: <div _ngcontent-yrc-c26="" class="footer">...</div>

如何解决此问题(在UI模式下工作).这是我的代码

how can I resolve this issue (working in UI mode). this is my code

WebDriver driver = getWebDriver();
        WebElement element;
        Thread.sleep(60000);
        element = driver.findElement(By.xpath("//label[@formcontrolname='reportingDealPermission']"));
        element.click();

为什么硒中没有移动到元素并破坏所有层的操作.这是用户界面.这是在UI模式下工作的,而不是在无头模式下工作,睡眠了6分钟并且无法解决,所以这不是时间问题

why in selenium there is no operation to move to the element and break all layers. this is the UI. this is working in UI mode not working in headless mode, made sleep for 6 minutes and not resolved so this is not time issue

推荐答案

此错误消息...

org.openqa.selenium.ElementClickInterceptedException: element click intercepted: Element <label _ngcontent-yrc-c26="" formcontrolname="reportingDealPermission" nz-checkbox="" class="ant-checkbox-wrapper ng-untouched ng-pristine ng-valid" ng-reflect-name="reportingDealPermission">...</label> is not clickable at point (161, 562). Other element would receive the click: <div _ngcontent-yrc-c26="" class="footer">...</div>

...表示在所需元素上的 click 被其他某个元素拦截了.

...implies that the click on the desired element was intercepted by some other element.

理想情况下,在对任何元素调用 click()时,您需要诱导定位器策略:

Ideally, while invoking click() on any element you need to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:

  • cssSelector :

new WebDriverWait(getWebDriver(), 10).until(ExpectedConditions.elementToBeClickable(By.cssSelector("label[formcontrolname=reportingDealPermission][ng-reflect-name=reportingDealPermission]"))).click();

  • xpath :

    new WebDriverWait(getWebDriver(), 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//label[@formcontrolname='reportingDealPermission' and @ng-reflect-name='reportingDealPermission']"))).click();
    

  • 更改为 headless 后,如果仍然无法正常工作并且仍然出现异常,则还可以考虑以下几种其他措施:

    After changing to headless if it still doesn't works and still get exception there still a couple of other measures to consider as follows:

    • Chrome browser in Headless mode doesn't opens in maximized mode. So you have to use either of the following commands/arguments to maximize the headless browser Viewport:

    • 添加自变量 start-maximized

    ChromeOptions options = new ChromeOptions();
    options.addArguments("--headless");
    options.addArguments("start-maximized");
    WebDriver driver = new ChromeDriver(options);
    

  • 添加参数-window-size

    ChromeOptions options = new ChromeOptions();
    options.addArguments("--headless");
    options.addArguments("--window-size=1400,600");
    WebDriver driver = new ChromeDriver(options);
    

  • 使用 setSize()

    ChromeOptions options = new ChromeOptions();
    options.addArguments("--headless");
    WebDriver driver = new ChromeDriver(options);
    driver.manage().window().setSize(new Dimension(1440, 900));
    

  • 您可以在中找到详细的讨论无法在无头模式下最大化Chrome窗口

    查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆