Reputation: 4831
I see this only in Chrome.
The full error message reads:
"org.openqa.selenium.WebDriverException: Element is not clickable at point (411, 675). Other element would receive the click: ..."
The element that 'would receive the click' is to the side of the element in question, not on top of it and not overlapping it, not moving around the page.
I have tried adding an offset, but that does not work either. The item is on the displayed window without any need for scrolling.
Upvotes: 483
Views: 708439
Reputation: 6052
For anyone coming across this in Laravel Dusk - which is based on Selenium and ChromeDriver - this long-standing problem occurs about 50% of the time when using the scrollIntoView()
method to scroll an element button into view, but seems to be permanently fixed by adding the --disable-smooth-scrolling
option to DuskTestCase.php
:
$options = (new ChromeOptions)->addArguments(collect([
"--window-size=1920,1080",
"--ignore-certificate-errors",
"--disable-smooth-scrolling" // add this
])->unless($this->hasHeadlessDisabled(), function ($items) {
return $items->merge([
"--disable-gpu",
"--headless",
]);
})->all());
Upvotes: 0
Reputation: 11
I've struggled with the same issue for hours now and I finally found the way to solve it!
simply add the following code after the scroll:
await driver.sleep(2500)
You can change the timing according to your likings. I set it as 2.5s and it now works perfectly fine. Hope it helps! :D
Upvotes: 0
Reputation: 4249
This is caused by following 3 types:
1. The element is not visible to click.
Use Actions or JavascriptExecutor for making it to click.
By Actions:
WebElement element = driver.findElement(By("element_path"));
Actions actions = new Actions(driver);
actions.moveToElement(element).click().perform();
By JavascriptExecutor:
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("scroll(250, 0)"); // if the element is on top.
jse.executeScript("scroll(0, 250)"); // if the element is on bottom.
or
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("arguments[0].scrollIntoView()", Webelement);
Then click on the element.
2. The page is getting refreshed before it is clicking the element.
For this, make the page to wait for few seconds.
3. The element is clickable but there is a spinner/overlay on top of it
The below code will wait until the overlay disppears
By loadingImage = By.id("loading image ID");
WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);
wait.until(ExpectedConditions.invisibilityOfElementLocated(loadingImage));
Then click on the element.
Upvotes: 395
Reputation: 140
Debugging "Element is not clickable at point" error
To handle this error scroll down using this code.
browser.execute_script("window.scrollTo(0, 300);")
Upvotes: 0
Reputation: 350
Today I got the same kind of issue. You don't believe me if i say how i solved the issue.
By maximizing the browser size
Yes, it is a pointer issue that means the size of the browser. For that, you just need to maximize the window size manually or through the code.
Upvotes: 7
Reputation: 121
There may be lots of factor which will throw this error. Firstly, the dom may be changed after selenium webdriver captured the element or all the java scripts used in elements is not loaded successfully before capturing the element. To fix this we need to use javascript wait or ajax wait like as follow.
wait = new WebDriverWait(driver, 30);
wait.until((ExpectedCondition<Boolean>) wd -> ((JavascriptExecutor) wd).executeScript("return document.readyState").equals("complete"));
e_driver = new EventFiringWebDriver(driver);
Secondly, most of the engineers of companies providing software qa services try using java script executor for the click action.
If this also doesn't work then perform action using Actions class.
Upvotes: 1
Reputation: 2119
This can also happen if you are trying to click on a input
or button
that is disabled
, in that case there nothing overlapping the element, but it's not clickable.
Upvotes: 0
Reputation: 2640
I was having this exact issue when clicking a button within an Angular Material menu. Whenever I clicked a button inside a menu, the .cdk-overlay-pane
would receive the click. The solution is to increase the z-index
of buttons inside the menu.
.cdk-overlay-pane button {
z-index: 1001;
}
Upvotes: 1
Reputation: 364
I was getting this error when running tests headless with xvfb-run. They were working flawlessly locally. Using chrome, versions of webdriver / chromedriver / chrome / java etc all identical.
The ‘won’t fix’ bug in chromedriver - GitHub Link pointed out by Tony Lâmpada suggested this may be related to what is / isn't visible on the screen.
Help message for xvfb-run shows the following:
-s ARGS --server-args=ARGS arguments (other than server number and
"-nolisten tcp") to pass to the Xvfb server
(default: "-screen 0 640x480x8")
Changing the resolution for xvfb made the error go away:
xvfb-run -s "-screen 0 1280x1024x16" ...
Upvotes: 13
Reputation: 5459
There seems to be a bug in chromedriver for that (the problem is that it's marked as won't fix) --> GitHub Link
(place a bounty on FreedomSponsors perhaps?)
There's a workaround suggested at comment #27. Maybe it'll work for you-
Upvotes: 50
Reputation: 309
If you are having this issue with a modal (pop-up), note that it may be that another element with the same properties exists underneath the current top level modal. This caught me out, just increase the specificity of your selector to reduce the scope to that of the modal you are trying to click only.
Upvotes: 1
Reputation: 103
This might help someone who is using WebdriverIO:
function(){
var runInBrowser = function(argument) {
argument.click();
};
var elementToClickOn = browser.$('element');
browser.execute(runInBrowser, elementToClickOn);
}
Source : https://www.intricatecloud.io/2018/11/webdriverio-tips-element-wrapped-in-div-is-not-clickable/
Upvotes: 0
Reputation: 17553
You need to use focus or scroll on that element. You also might have to use explict wait.
WebElement firstbutton= driver.findElement(By.xpath("Your Element"));
Actions actions = new Actions(driver);
actions.moveToElement(element);
actions.perform();
OR
The element is not clickable because of a Spinner/Overlay on top of it:
By loadingImage = By.id("loading image ID");
WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);
wait.until(ExpectedConditions.invisibilityOfElementLocated(loadingImage));
OR
Point p= element.getLocation();
Actions actions = new Actions(driver);
actions.moveToElement(element).movebyoffset(p.x,p.y).click().perform();
OR
If still not work use JavascriptExecutor
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", firstbutton);
Upvotes: 22
Reputation: 288
I was also stuck for two days because of the same reason, actually Scrolling will make it work, because may be the data couldn't load properly, which may cause the same error again and again.
What I did is, I scroll down randomly, once with (0,-500), then (0,400), then (0.-600), you may give these scroll value according to your use. Just scroll it where you have the content to click.
driver.execute_script("scrollBy(0,-500);")
sleep(5)
driver.execute_script("scrollBy(0,400);")
sleep(5)
driver.execute_script("scrollBy(0,-600);")
sleep(5)
It really worked :)
Upvotes: 2
Reputation: 406
Try to maximize the browser when you are working with resolutions greater than 1024x768.
driver.manage().window().maximize();
Upvotes: 2
Reputation: 54
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(15));
wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.<Id or anything>));
Hope this helps.
Upvotes: 0
Reputation: 871
The reason for this error is that the element that you are trying to click is not in the viewport (region seen by the user) of the browser. So the way to overcome this is by scrolling to the desired element first and then performing the click.
Javascript:
async scrollTo (webElement) {
await this.driver.executeScript('arguments[0].scrollIntoView(true)', webElement)
await this.driver.executeScript('window.scrollBy(0,-150)')
}
Java:
public void scrollTo (WebElement e) {
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeAsyncScript('arguments[0].scrollIntoView(true)', e)
js.executeAsyncScript('window.scrollBy(0,-150)')
}
Upvotes: 4
Reputation: 597
In Rselenium, this happened with code successfully used many times when a link was positioned at the top window border. Simple solution was to use sendKeysToElement() as follows.
if (unlist(webElem$isElementDisplayed())) {
webElem$sendKeysToElement(list(key = "up_arrow")) # Add "up arrow"..
webElem$clickElement() # ... before $clickElement
Upvotes: 0
Reputation: 1744
In my case, it worked in Firefox but failed in Chrome. In Chrome, it got fixed after updating Chrome driver version to the latest.
Upvotes: 0
Reputation: 131
I, too, wrestled with this problem. Code works fine in FF, fails on Chrome. What I was trying to do was to click a tickbox - if it wasn't in view, I'd scroll to view and then click. Even scrolling into view works in Chrome, only the bottom few pixels of the tickbox wasn't visible so webdriver refused to click on it.
My workaround is this:
WebElement element = _sectorPopup.findElement(...);
((Locatable) element).getCoordinates().inViewPort();
try {
element.click();
} catch (Exception e) {
new Actions(getWebDriver()).sendKeys(Keys.PAGE_DOWN).perform();
element.click();
}
Chrome also has issues with sendKeys, using Actions is sometimes necessary. Obviously, you need to know which direction and how much you need to go so your mileage may vary. But I prefer this to the javascript hack, so I'm posting it here in case someone else will find it useful.
Upvotes: 13
Reputation: 501
I had the same issue, tried all offered solutions but they did not work for me. eventually I used this:
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("var evt = document.createEvent('MouseEvents');" + "evt.initMouseEvent('click',true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0,null);" + "arguments[0].dispatchEvent(evt);", findElement(element));
Hope this helps
Upvotes: 40
Reputation: 1320
You can also use JavaScript click and scrolling would be not required then.
IJavaScriptExecutor ex = (IJavaScriptExecutor)Driver;
ex.ExecuteScript("arguments[0].click();", elementToClick);
Upvotes: 92
Reputation: 41180
If you have jQuery
loaded on the page, you can execute the following javascript command:
"$('#" + element_id + "').click()"
Example using python executor:
driver.execute_script("$('#%s').click()" % element_id)
Upvotes: 3
Reputation: 939
I do a kind of brute force of clicks and it works for me.
try:
elem.click()
except:
print "failed to click"
size = elem.size
mid_of_y = int(size["height"])/2
stepts_to_do_to_left = int(size["width"])
while stepts_to_do_to_left > 0:
try:
print stepts_to_do_to_left, mid_of_y
action = webdriver.common.action_chains.ActionChains(driver)
action.move_to_element_with_offset(elem, mid_of_y, stepts_to_do_to_left)
action.click()
action.perform()
print "DONE CLICK"
break
except:
pass
Upvotes: 2
Reputation: 2515
I was getting the same issue while running selenium script in python. Here is what I used to click on the element:
from selenium.webdriver.common.action_chains import ActionChains
ActionChains(driver).click(element).perform()
Upvotes: 11
Reputation: 282
Explanation of error message:
The error message simply says, that the element you want to click on is present, but it is not visible. It could be covered by something or temporary not visible.
There could be many reasons why the element is not visible in the moment of the test. Please re-analyse your page and find proper solution for your case.
Solution for particular case:
In my case, this error occures, when a tooltip of the screen element i just clicked on, was poping over the element I wanted to click next. Defocus was a solution I needed.
element.blur()
on the element poping the tooltip, which would make the tooltip disapear. Upvotes: 3
Reputation: 20011
When using Protractor this helped me:
var elm = element(by.css('.your-css-class'));
browser.executeScript("arguments[0].scrollIntoView();", elm.getWebElement());
elm.click();
Upvotes: 9
Reputation: 617
I met this because a loading dialog cover on this element. I simplely solve it by add a waiting before working with the this element.
try {
Thread.sleep((int) (3000));
} catch (InterruptedException e) {
//
e.printStackTrace();
}
Hope this help!
Upvotes: 3
Reputation: 1977
After testing all mentioned suggestions, nothing worked. I made this code. It works, but is not beautiful
public void click(WebElement element) {
//https://code.google.com/p/selenium/issues/detail?id=2766 (fix)
while(true){
try{
element.click();
break;
}catch (Throwable e){
try {
Thread.sleep(200);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
}
public void click(String css) {
//https://code.google.com/p/selenium/issues/detail?id=2766 (fix)
while(true){
try{
driver.findElement(By.cssSelector(css)).click();
break;
}catch (Throwable e){
try {
Thread.sleep(200);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
}
Upvotes: 2
Reputation: 945
If you're using the line below in your conf.js file, please comment it out and try again
browser.ignoreSynchronization = true;
Upvotes: 0