Reputation: 1237
I am having an issue with selenium, testing angular site.
I want to press the pub name field, in this screen:
As you can see this is a side menue that is opened,
and this is the Html:
I try to wait the element to be clickable, and it passed it. This is my code:
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");
}
And this is the exception:
: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>
I tried also to made selenium press esc button and still this is the error, how can I overcome this issue?
How can I know where to click that element will be free to click where I need him to click This is not waiting issue since when I debug I WAIT more times and still get this error
Regards
Upvotes: 5
Views: 24008
Reputation: 1
Try to play with driver.set_window_size(1900, 1080), as You see I changed it to almost fullscreen but not a full and it resolved the issue
Upvotes: 0
Reputation: 1383
I finally found the reason, the element is not in front of the view, which means you have to scroll to make it in front of the window and then it becomes clickable. Your situation may differ but in my case this was the reason.
Upvotes: 0
Reputation: 539
I recently ran into a similar issue. I do not use Selenium for testing but rather as an automated way of retrieving data from a website for a project. I ran into the same "ElementClickInterceptedError" error when running under certain situations such as through Task Scheduler where the browser window is hidden and its geometry is most likely causing the hidden element issue. As I was clicking on links to open pages in another tab, I wound up scrapping the concept of "clicking" and instead retrieving the link via getAttributes("href") and then calling executeScript("window.open(), 'target');") to open the link. Then I switch to the window and grab my data. The error has never returned since I gave up clicking.
Upvotes: 0
Reputation: 3790
You can sometimes get around blocked clicks by sending a space or enter bar press. Try:
element.sendKeys(Keys.SPACE);
Or
element.sendKeys(Keys.ENTER);
However looking at the class of the element blocking the click, it might be a notification in which case you will have to close the notification first. Some answers explaining how to do that have already been posted.
Upvotes: 2
Reputation: 2760
This issue occurs due to following situation :
Use Following for browser size or view port:
browser.manage().window().setSize(1600, 1000);
browser.actions().mouseMove(element).click();
Note : If above does not work try chaining perform() method too
browser.actions().mouseMove(element).click().perform();
For wait issue :
browser.driver.sleep(3000)
Note : It is not a standard way of putting or implementing a wait
Best way is :
WebDriverWait wait = new WebDriverWait(driver,60);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("xpath")));
For Pop up / alert :
Handle the window or alert and then perform the desired operation
Handle window :
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
});
});
Handle Alert :
Accept :
browser.driver.switchTo().alert().accept();
Dismiss :
browser.driver.switchTo().alert().dismiss();
Upvotes: 2
Reputation: 1761
the exception message is indicating that a specific element is in front of your target. I don't see that in either screenshot, but clearly it's showing up when the test runs.
You should watch a run w/out your debugger just to see if there's a notification that pops up, intercepts that automated click, and then goes away.
You may need to wait for the notification and dismiss that before you can click on your input.
Upvotes: 2