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'

5
  • Are you able to see the ID (BCA-button) in the DOM? Commented Oct 10, 2019 at 20:09
  • Also why you need 2 drivers, are you testing it in IE and Chrome? if your testing it IE please remove Chrome. Commented Oct 10, 2019 at 20:16
  • Yes I can see the ID. I removed the Chrome driver. Still no luck. Commented Oct 11, 2019 at 0:43
  • Please make sure InternetExplorerOptions.IntroduceInstabilityByIgnoringProtectedModeSettings should be true and you should have same protected mode for all(internet, Local Intranet, Trusted site and Restricted Site). Commented Oct 11, 2019 at 9:13
  • Also make sure zoom of your home IE and office IE is same. Commented Oct 11, 2019 at 9:19

6 Answers 6

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

Sign up to request clarification or add additional context in comments.

Comments

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;

1 Comment

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'.
0

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

3 Comments

It timed out after 10 seconds. Added snapshot.
Can you send me the link and xpath?
I fixed by adjusting the display settings to 100% zoom level.
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.

Comments

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?

Comments

0

Try implicit wait

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.