Selenium IWebElement.Click() doesn't work intermittently - c#

So this is similar to Click() method will not always work but there are several vital differences:
Not a timing issue because I repeatedly try to click it until success
No exception is thrown, just nothing happens
Using a JS click on the same element works - executor.executeScript("arguments[0].click();", element);
Using button.SendKeys(Keys.Return) instead works.
Displayed: true and Enabled: true
Only button.Click() doesn't work. I've stopped the application at a breakpoint and am testing it via the Immediate Window right now. I can see how Click() has no effect and doesn't throw an exception, but javascript click() and SendKeys() work.
Some additional info:
I'm using InternetExplorerDriver on IE11
I'm running the tests on Windows Server 2012 through Remote Desktop
It happens only intermittently. I remember switching Alt+Tab while the tests are running whenever it's happened but I don't know if this is the reason.
Any idea what is happening?
Edit: I noticed at one point that the first click pushes down the button (visibly) but it doesn't get click. The second click succeeds, however. Earlier Click() did not succeed, no matter how many times I executed it.
Edit 2: OK, now I've nailed it - if I click on the browser window, then I click to Visual Studio, then the first Click() doesn't work. Subsequent clicks all work, even if VS is still focused. Switching from VS to notepad and then to VS does not trigger it, only switching to IE and then back to VS.
It's as if it's not the problem that IE doesn't have focus, it's about having it and then losing it, then the next Click() will fail.

In my case the contol was partially overlapped with another div, and the webDriver clicked in the middle of control but hitted the div. Could you please check maybe it is your case.

Related

Selenium Webdriver click and send keys etc dont work on Google Chrome Version 78.0.3904.87

Google chrome automatically updated to Version 78.0.3904.87 yesterday and i now seem to have a problem with Selenium Webdriver.
When i run my tests in Visual Studio, the click events seem to occur but the expected result on screen does not happen e.g. clicking a link passes through the code (link.Click) successfully with no failure but the link does not get clicked on screen.
When i run the same test in Debug mode and Step Into each section of code it works fine, its as if selenium is running too fast for the browser (i have an implicit wait built in but its irrelevant, the element is there its just not clicking properly). I'm also finding things like sendKeys does not populate the field though it passes through the code successfully, again fine when stepping into it in Debug mode.
I've tried updating my Chromedriver to the version for V78 but this has made no difference
Similar problem here but my issue is not restricted to pdfs only
Chromedriver 78 cant find element in pdf
My team is running into the same issue. The issue seems to be the time between our WebDriverWaits and our Clicks -- the waits seem to be passing through instantaneously in cases they should not and then any Click element call (or action) hovers over what we want to click on but doesn't actually click.
I finally got to the bottom of this with our setup and it turned out to be the --enable-automation flag that seemed to be causing page flickering on page load.
After adding excludeSwitches: ['enable-automation'] to my config it has resolved the issue.

c# click button web browser visual studio

I hit another bump
webBrowser1.Document.GetElementById("submit_button").InvokeMember("click");
When it runs the button moves in the browser but it still do not work, I have to click the button twice that runs the code then it works
I tried using
webBrowser1.Document.GetElementById("submit_button").Focus();
webBrowser1.Document.GetElementById("submit_button").InvokeMember("click");
still not working
I think I need some kind of double click instead of only clicking once
As long as you are sure you have the proper ID for the element then the issue may just be that the "click" member is being invoked before the page has loaded.
Try this to be sure the document is loaded:
if (webBrowser1.ReadyState==WebBrowserReadyState.Complete)
webBrowser1.Document.GetElementById("submit_button").InvokeMember("click");
If it is a double click that you need, possibly try invoking the click twice with a sleep in between of a couple seconds? It is not the cleanest method though..

Firefox WebDriver randomly not actually executing clicks

Our Selenium tests were developed in C# and were running just fine for months but recently we noticed that a number of tests started failing when executed with Firefox WebDriver.
After investigating the test results and executing tests locally we noticed that from time to time clicks on random elements are executed (we can tell because the visual state of the button or the link changes to what looks like a clicked element)
Browser console does not indicated any errors. WebDriver logs show that click was executed.
Will be grateful for any help.
Edit:
Version of Selenium WebDriver - 2.53.0
Versions of Firefox - (tried few) 33.0.1, 43.0.1, 45.0, 46.0.1
Firefox scale 100%
tried with native events on and off
tried with additional implicit waiting before click
You question is not very specific, so I'll try to offer possible ways you can choose to resolving it.
You didn't indicate which driver and browser versions you used. If you didn't observe failures for months ant suddenly they appeared, my first guess would be that FF version you use on test machine(s) got updated (or driver version in tests was changed), and new combination can work differently. I had situation like this when tests behavior changed, updating driver version helped.
Another option would be to try and see which webelements get misclicked more often than others and insert instructions that check if they are displayed before executing actual click.
Also, try to do step-by-step debugging (if you haven't already) and see if you observe wrong clicks then
One thing we've seen in our testing is that if we're clicking around on the VM while a Selenium test is running on our VM, it can actually prevent clicks from going off.
But another thing we've encountered is that the clicks are often not working where they should be, so you can counter this by using JavaScript clicks instead of Selenium.
For elements that fail regularly, switch the element.Click() to a method utilizing the code below:
IJavaScriptExecutor executor = driver as IJavaScriptExecutor;
executor.ExecuteScript("arguments[0].click();", ElementToClick)
So the problem was that click does not work even when clicking manually so we'll be investigating in that direction.

selenium webdriver c# strange behaviour

I am using Selenium Web Driver and encountered following exception while trying to click a proper element in web browser: Unable to locate element.
XPaths are 100% correct.
The strange thing is it is working ok when:
In debug mode.
After clicking Continue in VS when exception appears.
When i am moving mouse manually on the screen.
I would be grateful for any help.
EDIT: Thread.Sleep doesnt help. I am trying to click decrease Year button in web calendar. It works first time, but freezes the second time. But the object is still there. So i dont understand how it can be not visible.
The driver is trying to locate the element before it loaded. Try waiting for it before clicking.
wait.Until(ExpectedConditions.ElementIsVisible(By.XPath(path))).Click();
There are a few things you can try:
1-try a selector by ID instead of the xpath. Maybe new elements are being rendered and making the xpath didn't find the element.
2-implement a retry pattern
3-use thread sleep to let the page being full rendered.

selenium InternetExporerDriver some elements click not consistently diring

So I have some tests in Selenium using the InternetExplorerDriver implementation of IWebDriver. Many of my objects respond to IWebElement.Click() well and consistently. I have anchors that click reliably for instance. I am writing some new stuff for clicking on a td. That is the element where the event handler is called says Mr Developer of the application under test.
The thing is it SEEMS to only fire click event and present the resultant hidden div when I am debugging the code but not when simply running it. There is not error thrown when the click is attempted.
I know that this is not a timing issue because there is something slow that is happening right before this test which allows the page to fully load.
Any other thoughts? Thanks.
Sorry folks for wasting your time. Operator error.

Categories