Click button does not work after upgrade to selenium 2.48.0
Doing test automation on a Ember.js web application:
I have a button which is covered by a <div> with a cooky notification. It looks something like this:

With Selenium 2.47.1 clicking on that button works as expected in Firefox. With Selenium 2.48.0 clicking this button does not work in Firefox, although there is no exception or error. It's like selenium thinks that the click worked properly but actually the click had no effect. Here the Robot Framework log:

The structure of HTML is something like this:
<header>...</header>
<main>
<div>
::before
<form>
<button>Last check</button>
</form>
::after
</div>
</main>
<div>
<div class="cookie-notification">
::before
<a href="http://...">Close</a>
::after
</div>
</div>
Just for comparison - executing the same click with Selenium 2.47.1 in Chrome results in a WebDriverException:

Traceback (most recent call last):
File "<string>", line 2, in click_button
File "C:\Python27\lib\site-packages\Selenium2Library\keywords\keywordgroup.py", line 15, in _run_on_failure_decorator
return method(*args, **kwargs)
File "C:\Python27\lib\site-packages\Selenium2Library\keywords\_formelement.py", line 316, in click_button
element.click()
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 69, in click
self._execute(Command.CLICK_ELEMENT)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 448, in _execute
return self._parent.execute(command, params)
File "C:\Python27\lib\site-packages\Selenium2Library\webdrivermonkeypatches.py", line 11, in execute
result = self._base_execute(driver_command, params)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 196, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 181, in check_response
raise exception_class(message, screen, stacktrace)
System configuration I:
- Microsoft Windows 7 64 bit
- Firefox 41.0.2
- Selenium 2.47.1
- selenium2library 1.7.4
- Robot Framework 2.9.2
==> click
<button>works
System configuration II:
- same as configuration I but
- Google Ghrome Version 46.0.2490.80 m
==> click
<button>does not work, WebDriverException
System configuration III:
- same as configuration I but
- Selenium 2.48.0
==> click
<button>does not work, no error/exception
This is due to the change https://github.com/SeleniumHQ/selenium/commit/0eec81da52ba4dfb16de590e6e82ebafa452416f, which makes Selenium more closely resemble a user when interacting with elements. You could try scrolling the element into view before attempting to click it. /cc @barancev
I had the exact same issue yesterday and I did indeed try scrolling to the element first before clicking and it still didn't work. I changed my webdriver to Chrome and the test passed which then led me to believe this issue was created in the recent update.
There is no possibility to scroll down in my case. My solution was to downgrade to Selenium 2.47.1
I wonder how a real user can click this button if it can't be scrolled into view?
I think I have a similar issue ... #1166
@barancev Real user can close the cooky notification by clicking the X on the right. The button is then uncovered and can be clicked. For my automated test I need to implement extra logic to handle this.
@davehunt Thanks for the hint on 0eec81d. Does that mean that by me descriped behavier is intended and should be understood as a feature?
If so, then I would suggest to give the user a notification or exception like the one of Chrome webdriver: Element is not clickable at point (x, y). Other element would receive the click: <div class="classname">...</div>. This would make it easier for the user to understand what happened.
This is no feature and it made us roll back to 2.47 also. The argument "simulating what the user can do" is overused to the detriment of ease of use. Depending on the overlapping element a real user could just scroll the page a bit or close the overlapping element. At least the scrolling would be something FirefoxDriver should be doing automatically after this change. Or how should I guess beforehand when a page is accidently scrolled to the wrong position?
This behaviour in ChromeDriver is annoying, but in Firefox it is now even worse since it simply clicks and nothing happens instead of at least throwing an exception like ChromeDriver. With webelement.click() I expect the click to go to the WebElement and not to the position of the WebElement. If I explicitly want to click its position I can achieve that with the Actions class.
If you make such changes you should provide a possibility to disable this new behaviour for compatibility purposes.
If you want to "click" an element that is hidden behind some other element you can use JavascriptExecutor. It is close to impossible to implement autoscrolling that could resolve overlapping.
Hi,
Element is not clickable at (x,y) co-ordinate seems to be an old Issue 2766, which we have solution. I have the same problem and i tried below solution.
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);
More reliable solution would be
Waitfor the Element to untill it was stable by any of the Expectedconditions and then do scroll on weblement as below. ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);
Regards Malli
On Fri, Oct 30, 2015 at 8:28 PM, Alexei Barantsev [email protected] wrote:
If you want to "click" an element that is hidden behind some other element you can use JavascriptExecutor. It is close to impossible to implement autoscrolling that could resolve overlapping.
— Reply to this email directly or view it on GitHub https://github.com/SeleniumHQ/selenium/issues/1202#issuecomment-152547947 .
I'm also seeing this, where an element is temporarily over the target element. It took too long for me to confirm exactly what was going on (although I suspected it almost immediately). The patch in #1211 helped with my confirmation. In my case, I've decided that the proper solution would be for the application under test to give a suitable indication that the obstructing element is not displayed. Due to the initial state of this element not being displayed, there's no appropriate waits that I can use - I even experimented with executing JavaScript with a MutationObserver. The project in question is not actively being developed, so I'll open an issue against it, but likely just add a sleep to my test suite. If anyone's interested, here's how to reproduce my issue:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Firefox()
wait = WebDriverWait(driver, 10)
driver.get("http://beta.123done.org/")
main_window = driver.current_window_handle
for i in range(5):
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "#signinhere button"))).click()
wait.until(lambda d: len(d.window_handles) > 1)
driver.switch_to.window(list(filter(lambda w: w != main_window, driver.window_handles))[0])
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "#authentication_email"))).send_keys("[email protected]")
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "p.submit button.isStart"))).click()
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "#authentication_password"))).send_keys("dsadadawdsda")
submit = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "p.submit button.isTransitionToSecondary"))).click()
assert wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "#cannot_authenticate"))).text == "Password incorrect"
driver.close()
driver.switch_to.window(main_window)
driver.quit()
Thanks to @p0deje for his patch in #1211 and also to @barancev who was able to confirm that he saw this issue whilst I was investigating it.
I have also observed this behavior in 2.28.2, which is compounded by Selenium scrolling an element too far, making it appear underneath a page's floating header (such as with a navigation bar). I was able to reproduce the bug with the page http://www.redkitetechnologies.com/services/
This bug makes 2.28.2 unusable in my company.
Expected
The element which was specified by xpath is clicked on
Actual
The element is scrolled behind the page header. The location where the element was scrolled to is clicked. This results on a click on the page header, instead of the element which was specified.
This simple perl script will reproduce the error (adjust things for your environment)
#!/usr/local/bin/perl
use warnings; use strict; use Utils::WebDriver; use Test::More tests => 1;
my $webdriver = Utils::WebDriver->new(browser_url => "http://www.redkitetechnologies.com/services/" ); $webdriver->set_window_size( 768, 1024 );
$webdriver->find('//[@id="post-22"]/div/section/div[3]/article/a/h2', 'xpath')->click; note ("Clicked the Solutions title and its page should be loaded"); like ( $webdriver->find( '//[@id="post-695"]/div/div/h1', 'xpath' )->get_text, qr/solutions/, "Correct page loaded after clicking Solutions" );
$webdriver->quit(); exit(0);
@TraceyC77 Selenium will scroll an element before interacting with it if it's not in view, and will align it with the top of the viewport. You could prevent this by proactively scrolling the element into view by using execute_script with some JavaScript such as: arguments[0].scrollIntoView(false); to align with the bottom of the viewport, or arguments[0].scrollIntoView(); window.scrollBy(0, 120); to align to the top and then scroll by the height of the header.
We have nearly 3000 tests running and none of the tests failing with 2.48 because of this change detects a defect or something that has to be changed in the application under test. So for us this change just causes work. And it's even worse since no error is thrown in case of a "wrong click". Again the request: please make it possible to disable this new behaviour.
PR #1211 merged, that makes Firefox to behave like Chrome (and unlike IE that clicks the topmost element and does not throw).
But I'll keep this issue open because I'm going to implement a capability to choose to desired behavior -- to throw (default) or to click the topmost.
Interesting, I have a very similar case that may be related to this. Chrome driver, c#.
There is a form and a buton under the form. This used to work fine, I guess it was scrolling automatically somehow to the button at the bottom of the screen and the buton could be clicked. But since a small addition to the form, where a new input is added dynamicaly based on some other inputs on the form, this stopped working and cannot find the buton at the bottom of the page. I just guess that maybe there is some calculation of the height of the page or elements positions for the view port, when the new input is dynamicaly added by javascript this extends the height of entire page, and then the buton goes below the original size and cannot be found.
+1 to fix or be able to disable.
Very frustrating issue to track down until I found this thread.
In our case, we have a floating header that is clickable. As forms are filled out, the page scrolls down. When attempting to click on Submit, it is behind the header and the change introduced in https://github.com/SeleniumHQ/selenium/commit/0eec81da52ba4dfb16de590e6e82ebafa452416f makes it click on the header and send the user back to the home page (most frequently).
For quite a while, we thought there were application issues and we were being redirected home because of an error that didn't log anything.
@barancev, the ideal case would be neither of your suggestions in https://github.com/SeleniumHQ/selenium/issues/1202#issuecomment-157643625. The browser should scroll until the desired element is clickable just like it does with filling out form fields, etc.
PR #1211 and your ideas work if it's impossible to scroll to get to the desired element (e.g. some overlay that needs to be closed first).
@ronwsmith, it is not always possible to make overlapped elements clickable by scrolling. I understand that you mean fixed position blocks, but it is only one of possible cases.
Thanks for the clarification. I think we're on the same page here.