0

I have this line of code.

driver.FindElement(By.Id("BCA-button")).Click();

This was working fine at 'home'.

I am using these libraries in C# Unit Test project.

using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.IE;

The same code stopped working in 'office' and gives this error.

OpenQA.Selenium.WebDriverException: 'Cannot click on element'

The only difference between my 'home' and 'office' environments are, I have bigger monitors in office and high speed internet.

Not sure, why these factors should affect this line of code. Same code was working yesterday in 'home' and it throws error in 'office' today.

Any thoughts ?

Added Snapshot for more clarity.

Here is another try.

I am using 'InvisibilityOfElementLocated'

Adam
  • 1,221
  • 4
  • 13
  • 27

6 Answers6

1

I found the problem. If the screen resolution display settings, text size is not 100% (recommended settings) then "Selenium Web Driver" fails to perform the click event.

Display Setting on Screen Resolution

Adam
  • 1,221
  • 4
  • 13
  • 27
0

Induce WebDriverWait and ElementToBeClickable()

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
IWebElement elebutton = wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("BCA-button")));
elebutton.Click();

You need to import this library.

using SeleniumExtras.WaitHelpers;
KunduK
  • 32,888
  • 5
  • 17
  • 41
  • I tried this. Same error. Added the snapshot. The same code was working yesterday. Do you think 'McAfee' plug-in will block the click event ? But still this was active always even at 'Home'. – Adam Oct 11 '19 at 00:13
0

I think the best way is to use XPath. You can create a delay until XPath element is found.

0

Different ways of Clicking on Element is explained nicely here : Selenium Web Driver & Java. Element is not clickable at point (x, y). Other element would receive the click

I always use the 5th way when element.click() doesn't work even when the element is available and explicit wait is applied to element.

Pratik
  • 357
  • 1
  • 9
0

The reason you are getting the exception:

OpenQA.Selenium.WebDriverTimeOutException: 'Cannot click on element'

Is that the WebDriver is waiting for the element, but cannot locate it before reaching the timeout limit.

Is there any other element wrapping or covering the element you are trying to click?

Agent Shoulder
  • 586
  • 8
  • 22
0

Try implicit wait

driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(50);