14

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>

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();

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

enter image description here

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Bastian
  • 1,089
  • 7
  • 25
  • 74

9 Answers9

18

This error message...

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>

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


Clicking an element

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();
    

Update

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:

    • Adding the argument start-maximized

      ChromeOptions options = new ChromeOptions();
      options.addArguments("--headless");
      options.addArguments("start-maximized");
      WebDriver driver = new ChromeDriver(options);
      
    • Adding the argument --window-size

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

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

You can find a detailed discussion in Not able to maximize Chrome Window in headless mode

  • Additionally, you can also wait for the intercept element to be invisible using the ExpectedConditions invisibilityOfElementLocated before attempting the click() as follows:

    • cssSelector:

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

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

References

You can find a couple of related relevant discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    I know and I use it, however after changing to headless it is not worked and after the wait clickable still get exception, only the java script worked – Bastian Jun 08 '20 at 13:41
  • @Bastian Checkout the answer update and let me know the status. – undetected Selenium Jun 08 '20 at 14:18
  • 1
    it solved it, I used options.addArguments("start-maximized"); and options.addArguments("--window-size=1920,1080"); I did not use the driver.manage().window().setSize(new Dimension(1920, 1080)); what id it the third one do? since I do not use it - @DebanjanB – Bastian Jun 09 '20 at 09:57
  • @Bastian `driver.manage().window().setSize(new Dimension(1920, 1080));` is just another way of setting the Browser Client [Viewport](https://www.w3schools.com/css/css_rwd_viewport.asp) – undetected Selenium Jun 09 '20 at 10:25
  • 1
    I face the same issue and element that i use have element id, so i tried with element id which is not working, then i have used xpath then its fine – user1767083 Oct 12 '21 at 11:28
  • My issue was I have a splash element sitting on top of the main page content, so `invisibilityOfElementLocated` helped me, thank you very much. – Alba Hoo Jan 19 '22 at 07:28
11

Try adding an explicit wait

WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//label[@formcontrolname='reportingDealPermission']"))).click();

and if this doesn't work then try using the JS Executor

WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//label[@formcontrolname='reportingDealPermission']"))); 
((JavascriptExecutor)driver).executeScript("arguments[0].click();", element);
Wilfred Clement
  • 2,674
  • 2
  • 14
  • 29
5

None of the above answers worked for me. Try using action class as follows:

WebElement element = driver.findElement(By.xpath("//div[@class='footer']"));
Actions actions = new Actions(driver);
actions.moveToElement(element).click().build().perform();
sagarp
  • 61
  • 1
  • 2
1

For this 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).

Another element receives the click:

Answer is to explicitly wait with javascript executor. This combination is working for me:

WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//label[@formcontrolname='reportingDealPermission']"))); 
((JavascriptExecutor)driver).executeScript("arguments[0].click();", element);
ouflak
  • 2,458
  • 10
  • 44
  • 49
1

WebDriverWait wait = new WebDriverWait(driver, 10); ---> has deprecated and it gives an error. Please use below instead:

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//label[@formcontrolname='reportingDealPermission']"))).click();

Ensure to import relevant items for the WebDriverWait and ExpectedConditions.

0

In my case "JavaScript" works:

WebElement ele = driver.findElement(By.xpath("(//input[@name='btnK'])[2]"));
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("arguments[0].click()", ele);

It was taken from: http://makeseleniumeasy.com/2020/05/25/elementclickinterceptedexception-element-click-intercepted-not-clickable-at-point-other-element-would-receive-the-click/

Alexis Gamarra
  • 4,362
  • 1
  • 33
  • 23
0

Answer is worked for me.

Please check the below sreenshot for the my problem reference. Below alert is comes in between the the my button and frame. enter image description here

  • 1
    WebElement ele = driver.findElement(By.xpath("(//input[@name='btnK'])[2]")); JavascriptExecutor jse = (JavascriptExecutor)driver; jse.executeScript("arguments[0].click()", ele); – inderjeet kumar Feb 15 '23 at 20:45
  • This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post. Please do not ask questions in the answer and take the tour and read How to Answer: https://stackoverflow.com/help/how-to-answer – borchvm Feb 21 '23 at 16:03
0

If still facing issue then try this, clicking using JSExecutor worked for me:

((JavascriptExecutor) driver).executeScript("arguments[0].click();", <web_element_object>);
Karansing
  • 47
  • 6
-1

In my case, nothing worked. Only the THREAD.SLEEP() method worked!

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Kunal Varpe Jan 02 '23 at 16:15