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?
    – stacktome
    CommentedOct 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.
    – stacktome
    CommentedOct 10, 2019 at 20:16
  • Yes I can see the ID. I removed the Chrome driver. Still no luck.
    – Adam
    CommentedOct 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).CommentedOct 11, 2019 at 9:13
  • Also make sure zoom of your home IE and office IE is same.CommentedOct 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

    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
    • 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
      CommentedOct 11, 2019 at 0:13
    0

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

    3
    • It timed out after 10 seconds. Added snapshot.
      – Adam
      CommentedOct 11, 2019 at 0:20
    • Can you send me the link and xpath?CommentedOct 11, 2019 at 5:43
    • I fixed by adjusting the display settings to 100% zoom level.
      – Adam
      CommentedOct 16, 2019 at 22:49
    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.

      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?

        0

        Try implicit wait

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

          Start asking to get answers

          Find the answer to your question by asking.

          Ask question

          Explore related questions

          See similar questions with these tags.