Caused by: org.openqa.selenium.ElementClickInterceptedException: element click intercepted: [duplicate] - selenium

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

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:
Selenium Web Driver & Java. Element is not clickable at point (x, y). Other element would receive the click
Element MyElement is not clickable at point (x, y)… Other element would receive the click

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

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

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

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.

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/

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

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

Related

The radio button is not getting selected with this HTML code for that. How to do that?

<input id="radio2" name="radioGroup" type="radio">
<label class="flRight" for="radio2">
::before
"Senior Citizen"
::after
</label>
WebElement senior = driver.findElement(By.id("radio2"));
senior.click();
Now the problem is the code is not able to click the desired element.
You need to induce WebdriverWait And to click on the radio button use JavaScript Executor since neither webdriver click nor action class is working
WebDriverWait wait = new WebDriverWait(driver, 20);
WebElement item=wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//label[#class='flRight' and #for='radio2']")));
JavascriptExecutor js= (JavascriptExecutor) driver;
js.executeScript("arguments[0].click();", item);
Try with this:
WebElement senior = driver.findElement(By.xpath(".//div[#class='radioBtn']/label[2]"));
WebElement close = driver.findElement(By.xpath(".//div[#id='nvpush_cross']"));
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.visibilityOf(close));
close.click();
senior.click();
Code didnt worked before because there is popup you need to close it.
Use WebDriverWait:
WebDriverWait wait = new WebDriverWait(driver, 20);
WebElement senior = wait.until(ExpectedConditions.elementToBeClickable(By.id("radio2")));
senior.click();
After seeing the WebSite it looks like the input is not the element you want to click rather the label...
So just change the senior var to:
WebElement senior = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[#id='RadioButton']//label[#for='radio2']")));
The best way to automate human actions in the case where the element is not clickable dew to other elements covering them is to use Actions:
WebElement senior = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[#id='RadioButton']//label[#for='radio2']")));
Actions actions = new Actions(driver);
actions.moveToElement(senior).click().build().perform();
(using JavascriptExecutor and executeScript doesn't realy click... it just invokes the method that can be good but not for testing...)
As a last resort use JavascriptExecutor:
JavascriptExecutor jse= (JavascriptExecutor) driver;
jse.executeScript("arguments[0].click();", senior);
Please try below solution :
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//label[#class='flRight' and #for='radio2']")));
Actions action=new Actions(driver);
action.moveToElement(element).click().perform();

Unable to Locate an element for Salesforce Lightning

Technology:
Salesforce
Lightning
Selenium webdriver
Html:
Code Trials:
driver.findElement(By.xpath("//a[#title='Acq Prospects']"));
driver.findElement(By.linkText("Acq Prospect"));
Error:
Unable to find an element
You simply need to wait object to be visible. You can use the following code;
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.Until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a[#title='Acq Prospects']")));
For more informations; link.
Note: Also ensure that there is no any element that overlay your object which you are trying to find.
To locate the desired element you need to induce WebDriverWait for the elementToBeClickable and you can use either of the following solutions:
cssSelector:
WebElement Acq_Prospects = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a.slds-context-bar__label-action.dndItem[href='/lightning/o/Acq_Prospect__c/home']")));
xpath:
WebElement Acq_Prospects = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[#class='slds-context-bar__label-action dndItem' and #href='/lightning/o/Acq_Prospect__c/home']")))

Unable to use elements within iframe after switching

I am using switching to an iframe using the below statements but on the final wait I get web element not found. Does anyone have any suggestions? I have trolled through google for about a day trying different techniques. None have worked so far
WebDriver driver = DriverFactory.getWebDriver()
WebDriverWait wait = new WebDriverWait(driver, 15)
driver.switchTo().defaultContent()
WebElement iframe = driver.findElement(By.cssSelector(".b-iframe__iframe"))
driver.switchTo().frame(iframe)
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(
'fieldset.radio-switch-group')))
Screen shot of HTML below image
As per the HTML you have shared to locate the desired WebElement you have to:
Induce WebDriverWait for the desired frame to be available and switch to it.
Induce WebDriverWait for the desired element to be visible and you can use either of the following solutions:
Using cssSelector:
new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.cssSelector("iframe.b-iframe__iframe[src*='securetest']")));
WebElement element = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("fieldset.radio-switch-group#balance-type")));
Using xpath:
new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[#class='b-iframe__iframe' and contains(#src,'securetest')]")));
WebElement element = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//fieldset[#class='radio-switch-group' and #id='balance-type']")));
Here you can find a relevant discussion on Ways to deal with #document under iframe

getting Element is not clickable at point (355, 160) exception

My script is failing because of the following exception.
org.openqa.selenium.WebDriverException: unknown error: Element is not
clickable at point (355, 160)
While loading the page if the element appears in the background, selenium tries to click and fails. I have used webdriverwait. Out of 10 times it fails around 3 times minimum.
How can I avoid/handle this without using Thread.sleep();
You should wait until invisibility of element using invisibilityOfElementLocated as below :-
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath('xpath of please wait loading...')));
After this you could perform click on target element
Hope it will work..:)
Use explicit wait
WebDriver driver = new FirefoxDriver();
driver.get("http://somedomain/url_that_delays_loading");
WebElement myElement = (new WebDriverWait(driver, 10))
.until(ExpectedConditions.presenceOfElementLocated(By.id("myElement")));
// or (new WebDriverWait(driver, 10)).until(
// ExpectedConditions.visibilityOfElementLocated(By.id("myElement")));
myElement .click();

Popup scroll not working in selenium webdriver

I am running my script in mozilla firefox I want to scroll popup I
applied so many methods but doesn't work for me
I used keys.tab to reach that element but it was unable to enter text in that textfield using senkeys("xyz#gmail.com)
I used scroll method
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.getElementById('youama-email').scrollIntoView(true);");
some exception occur
3.I used Moveto element method but got exception
WebElement element = driver.findElement(By.id("youama-email"));
Actions
actions = new Actions(driver);
actions.moveToElement(element);
actions.click();
actions.perform();
// Initialize Javascript executor
JavascriptExecutor js = (JavascriptExecutor) driver;
// Scroll inside web element vertically (e.g. 100 pixel)
js.executeScript("arguments[0].scrollTop =
arguments[1];",driver.findElement(By.id("<div-id>")), 100);
Please help me to scroll and enter into the email as well as other
fields that will appear after scroll [![enter image description
here][1]][1]
[1]: http://i.stack.imgur.com/D0hqI.png
Try this code. I think what you didn't do was to wait for the element to be visible which i did. See the below code. It is running correctly.
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://wyomingvapor.com/");
driver.findElement(By.xpath(".//*[#id='header']/div/div[2]/div/a[1]")).click();
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//*[#id='y-to-register']/input")));
driver.findElement(By.xpath(".//*[#id='y-to-register']/input")).click();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//*[#id='youama-firstname']")));
driver.findElement(By.xpath(".//*[#id='youama-firstname']")).sendKeys("xyz#gmail.com");
Thread.sleep(2000L);
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_TAB);
robot.keyRelease(KeyEvent.VK_TAB);
robot.keyPress(KeyEvent.VK_TAB);
robot.keyRelease(KeyEvent.VK_TAB);
robot.keyPress(KeyEvent.VK_X);
robot.keyRelease(KeyEvent.VK_X);
robot.keyPress(KeyEvent.VK_Y);
robot.keyRelease(KeyEvent.VK_Y);
robot.keyPress(KeyEvent.VK_Z);
robot.keyRelease(KeyEvent.VK_Z);
If you still stuck then do reply to me, Jyotsana.
Happy Learning :-)