WebDriver - element is not clickable Chrome
Asked Answered
O

8

12

I have following problem. I run test on Firefox and Chrome. On Firefox test run correctly but on Chrome SauceLabs give a message:

unknown error: Element is not clickable at point (717, 657). Other
element would receive the click: <div class="col-md-9 col-sm-12"
style="margin-top:8px;">...</div> (Session info: chrome=36.0.1985.125)
(Driver info: chromedriver=2.10.267521,platform=Windows NT 6.3 x86_64)

I choose element by unique css selector in both test in the same way:

driver.FindElement(By.CssSelector("button.btn-xs:nth-child(1)")).Click();

Any ideas what is wrong here?

Oraleeoralia answered 19/9, 2014 at 8:7 Comment(2)
did you try to wait for the element before the click?Ballon
the same behaviour after timeout.Oraleeoralia
G
18

I am assuming that you have the correct element you need, ie the XPath is correct. Here are few ways out:

  1. Try to Click on the parent element instead.
  2. Try .Submit() instead of .Click()
  3. Try to execute the JavaScript that will be executed on the OnClick event of the element you are trying to click.

I have used the 3rd way with success all the time.

Another one

  1. Do a .SendKeys(Keys.Enter) on that element (or a Space key)
Galingale answered 19/9, 2014 at 9:23 Comment(2)
1. does not work 2. does not work: no such element: "Element was not in a form, so could not submit."Oraleeoralia
Are you sure that the Element exists in the form, since by 2, you got that message? Anyways try 3Galingale
F
8

Since you've tagged the question as Google-Chrome too - I suppose that this is happening mostly with ChromeDriver. I had the same issues with one of my previous projects (Asp .Net MVC). I found that when some elements are not visible for this Driver if they are not in the screen_visible_area. Please note that they are loaded (HTML, CSS3, JS etc.) properly.

So after a lot of reading and testing, I found that my workaround is simply scroll to the WebElement - so it is in the visible part of the screen. Actually this issue was not for all elements and I didn't find better solution for it.

unknown error: Element is not clickable at point (..., ...) 

Is not descriptive error for this case, because like you I also thought that is Selector-related.

Just to be full answer - I had the same problems with IEDriver too. My implementation was to use the Browser scroll down/up options and just "send the screen" where the problematic element is.

Simple JSExecutor code that you can use:

WebDriver driver = new FirefoxDriver();
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("window.scrollBy(110,350)", "");

or

jse.executeScript("scroll(0, 250);");

or

driver.executeScript("window.scrollBy(110,350)", "");

Other topic-related useful resources are here.

Update

When it comes to the .sendKeys() I also used the browser accessibility features. All you need to do is just count how many TAB clicks your test need in order to get to the targeted web_element. Then just call .click().

Try this simple code:

element.sendKeys(Keys.TAB);

or

element.sendKeys("\t")

or

Actions builder = new Actions(driver);
builder.keyDown(Keys.TAB).perform()
Frenchpolish answered 19/9, 2014 at 9:37 Comment(5)
Okey, it is useful answer man, I will check it out maybe in the future tests;) Thanks!Oraleeoralia
It will be faster to do a .SendKeys() directly rather than scrolling down to the element and the doing a .Click() on itGalingale
Actually this was one of my custom-made solutions - please see my updated answer.Frenchpolish
Tried everything: scrolling, scroll wheel, etc. The only thing that works is Keyboard.SendKeys("{TAB}"); (as many times as needed to get the control showing on the screen.) Ridiculous!Chequered
I know :) did u tried raw JS with IJavascriptExecutor.ExecuteScript("click-elem-here");Frenchpolish
S
1

I realize this is a super old question, but it came up while searching a nearly identical problem in the present day. After attempting many of the fixes described here and getting new exceptions for my trouble (mostly stale element and http request timeouts) I stumbled across this issue on Selenium's GitHub.

As described in the post, Chrome had advanced beyond the abilities of my version of chromedriver.exe--my v2.30 driver had known issues with clicking elements due to changes in Chrome v61 scrolling mechanics. Updating to the latest chromedriver.exe solved all my problems.

tl/dr: ensure your version of chromedriver is compatible with the version of Chrome being tested.

Slander answered 2/11, 2017 at 13:43 Comment(0)
P
1

I was getting issue that login button is not clickable in chrome even xpath was correct. after browsing many sites, i came to the solution - use .submit() instead of .click() and it worked perfectly.

driver.findElement(By.xpath("//button[@id='loginBtn']")).click();
driver.findElement(By.xpath("//button[@id='loginBtn']")).submit();
Peipeiffer answered 16/5, 2019 at 13:20 Comment(0)
O
0

If you're doing anything complicated in your CSS, Chrome can get confused (this has happened to me) and think that the element you're trying to click is covered by another element even though this is not the case.

One way to resolve this is to help Chrome understand the situation correctly by adding z-indexes (you'll need to add relative or absolute positioning also) to unambiguously place the correct element on top of the other.

Overture answered 2/2, 2016 at 1:30 Comment(0)
A
0

For me, it was creating this command instead.

driver.FindElementByXPath("id('gender1')").SendKeys(Keys.Space);

For my case, I was interacting with radio control.

Ascertain answered 6/4, 2016 at 23:11 Comment(0)
C
0

I have had this problem on FF. This issue happens when your field is not in the view area. The slick way to resolve this issue is to zoom out your browser:

TheNotClickableField.SendKeys(Keys.Control + "-" + "-");

you might want to zoom out more or less according to your page size.

Cabanatuan answered 21/4, 2016 at 9:21 Comment(0)
A
-1

I. If the button is on the bottom of the page, the following code could be used to get you to the bottom via JavaScript from where the click can be executed:

(driver as IJavaScriptExecutor).ExecuteJavaScript("window.scrollTo(0,document.body.scrollHeight - 150)");

The same action could be done via C# with the Actions class provided by Selenium. This will get you to the bottom of the page----->

new Actions(Driver).SendKeys(Keys.End).Perform();

Keys.End could be switched with Keys.PageDown // Keys.Space

II. If you want to get to the exact position of the element you can:

1.Get the element's Y location---> var elementToClick = driver.findElement(By.{Anything}(""));

2.Execute the following JS---> (driver as IJavaScriptExecutor).ExecuteScript(string.Format("window.scrollTo(0,{0})", elementToClickYLocation.Location.Y));

3.Click the element---> elementToClick.click();

Adigun answered 25/8, 2017 at 9:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.