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 theclick()
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: