Selenium clicks on a wrong link (or does not click on a link at all) on certain machines - selenium

I am using Selenium WebDriver 2.5.0 (tried 2.13.0, it did not help).
I am trying to click on a link like this:
driver.FindElement(By.PartialLinkText("Customer - Creation").Click();
Before it worked, but I have tried to run the scripts after 3 weeks and
I observe 3 different behaviors on 3 machines:
Machine A: There is no click on the link at all, also there is no error.
Machine B: It clicks a different link! Sometimes one above, sometimes one below.
Machine C (Virtual): It works.
I have not fully tested this (spent half a day today), but did anyone stumble upon such a behaviour?
I have restarted my PC, re-added the Selenium libraries.
"SendKeys(Enter)" helps, but this issue happened not only to links, but to at least radio boxes as well, where "SendKeys(Enter)" does not work.
Please share your thoughts.
Update: Browsers are the same on at least 2 machines, Internet Explorer 8.0

Answered by nebehr.g...#gmail.com at Selenium Issues:
This issue keeps popping up from time to time and is usually returned with request for clarifications. The bottom line is, InternetExplorerDriver calculates coordinates of some objects incorrectly and clicks in the wrong place. One reason for this is zoom value other than 100%; however it is reproducible for some controls for 100% zoom as well.
I suppose it would be helpful if you could create a sample page to demonstrate this issue. In the meantime why don't you use Javascript click() method for offending controls?
http://code.google.com/p/selenium/issues/detail?id=3052

One other thing to check for is the screen resolution (not the desktop resolution but the system level size of text and icons). I have two laptops in my office that are you used for testing, one running Windows 7 and the other running Windows 10. On both, the screen resolution was greater than 100% and Selenium was having problems moving the mouse to the correct location for mouse events like click and hover. As soon as the screen resolution was set to 100%, all mouse actions worked correctly.
Windows 7: http://windows.microsoft.com/en-us/windows7/make-the-text-on-your-screen-larger-or-smaller?v=t
Windows 10: https://superuser.com/questions/951199/windows-10-system-font-size-change

There is a lot of useful info in Andrey's answer and in the Selenium issue he mentions at https://code.google.com/p/selenium/issues/detail?id=3052. Just to tie all those pieces of info together and offer a successful workaround...
I too am experiencing the issue of clicks occurring at the wrong screen coordinates -- four years after the OP first mentioned it! As others have said:
The issue is related to InternetExplorerDriver. I have the problem
when testing IE 9, but not Chrome, Firefox or even IE 8.
As mentioned in the Selenium issue, the website I'm testing uses frames.
I tried several workarounds suggested in this post and elsewhere. All of the following did NOT help:
Updating to the latest InternetExplorerDriver (version 2.47.0)
Maximizing the browser window.
Setting browser zoom to 100%.
Using an action chain, with or without move_by_offset, instead of WebDriver's click() method.
As suggested by Andrey, what DID help is using JavaScript instead of WebDriver's click() method. Here's a line of Python code that does the trick:
driver.execute_script("jQuery('{}').click();".format(css_selector))
This assumes that "driver" is an instance of Selenium WebDriver, and "css_selector" is a string identifying the element you want to click, and that jQuery is loaded.

Sounds like the element isn't present in the page's HTML, but is instead added dynamically once the page is loaded. What happens depends on how fast the machine is and how unique the text is. I'll bet that if you added a long sleep (e.g., a minute) you'd get the same result on all 3 machines. If so, that indicates the single most classic Selenium testing problem - trying to act on pages that aren't complete. You need to find an element to wait on that will guarantee the presence of the link you'd like to click on.

I just had the same issue in FireFox. The zoom was at 100% and the selection was by xpath an certainly correct. Turned out the problem disappeared when I maximized the browerwindow!
code :(python api)
self.driver.maximize_window()

Related

How to switch between 2 different tabs of browser in Selenium

I want to switch between 2 tabs of browser. Currently tried of getting number of window handles, but even though 2 tabs are open its shows as 1.
You never mentioned any language you are using. But, I use the following to handle some of my tests
Driver.SwitchTo().Window(Driver.WindowHandles.LastOrDefault());
Mine is C# but it would be pretty simple to convert.
Selenium can get windowhandles of those tabs whose origin is same....
if the web application origin is different then you'll not get window handle
If its from same origin then this issue may come in Internet Explorer 9-
I have come across this issue before in IE Browser..
You may also want to refer your company's security policy .. maybe it can be the cause to detach second window from the parent window....

Why doesn't pagingTextBox work in IE using dgrid pagination

Does anyone happen to know why the pagingTextBox doesn't work when using the dgrid pagination? It works fine in FireFox and Chrome but when hitting the enter key in the textbox in IE, it does nothing. I'm using IE 10, but also tried with IE 8. I need this functionality in all 3 browsers. Thanks.
The only event that the paging textbox listens for is change. Apparently, pressing enter registers this event on Chrome and Firefox but not IE. I'm not sure what the reasoning is behind that.
This seems like a legitimate issue to report on dgrid's GitHub issues page though. It shouldn't take too much effort to fix, even if it means listening for 2 types of events.

Move target out of bounds exception

I am writing tests for a web application and all went well until I had to choose an option from a menu and that option displays a drop down list when hovered or clicked. When I click an option from the drop down list, I get the following error:
MoveTargetOutOfBoundsException: Element cannot be scrolled into view
Does anyone know what this error is about and what I should look for in my code?
Selenium version 2.25.0, java version 1.6.0_31
I've been checking some selenium and google groups regarding this issue in older versions https://groups.google.com/forum/?fromgroups=#!topic/selenium-users/EuZ7a6_lB9Q
http://code.google.com/p/selenium/issues/detail?id=3075
http://code.google.com/p/selenium/issues/detail?id=4102
a more recent discussion
Is it a known issue for Selenium 2.25.0 or is there a way to fix it? I recently upgraded to Firefox 15.0 :|
Note: I found a temporary solution until someone magically fixes this...since I can't find where the problem is...
I run the code before that point where it crashes, I put it to sleep for 10 seconds, I manually click the menu and the option from the drop down list, the window I want is displayed and the code continues with actions from that point. It works for now...I hope this will be fixed since I can't believe that I can run a script in Selenium IDE but I can't run my java code in WebDriver ...this is crazy :|
I guess you are trying to click an element from a dropdown.
You should keep in mind, that Selenium helps you replicate exact human behavior. So if the code fails because the element is not visible, it is probably because the element is not visible.
To make it work, you might want to put a click command on the menu before the failing bit of code.
(to replicate the sleep 10 seconds manually click the menu button method you are using)
Once again, if you can show us your code and also the HTML snippet of the Menu section, we can provide an exact solution.
Maybe you're opening new popup window while opening select box.
This may help you:
WebDriver.FindElement(By.Id("someInputBox")).SendKeys("hello");
(IJavaScriptExecutor)WebDriver).ExecuteScript("document.getElementById('windowOpener_Button').click();");
WebDriver.SwitchTo().Window("newDisplayedWindowPopupName"); // continue to test

selenium webdriver stop working when click on different window

I'm using IE8 and webdriver.
The problem I have is every time webdriver runs I can't touch my computer. Basically the moment I click on a different window it stops working.
Because of this I can't run my code in debug mode with break point because I every time I go to Eclipse to manually execute the break point webdriver doesn't work anymore because IE8 is not selected.
With Firefox I'm able to do whatever I want but not with IE8. Is there anyway I can fix this problem with IE8?
Thank you!
The short answer is, "No, you can't fix this problem with IE at the moment." There are a number of reasons why window focus is incredibly important with the IE driver. The biggest reason is that you're using so-called "native events" when you're using the IE driver, which simulates mouse and keyboard events at the operating system level rather than just within the browser using, say, JavaScript, and the way IE processes native events is sometimes compromised if the browser window doesn't have focus. More information can be found in a presentation given at the 2012 Selenium Conference.
One approach to solving the problem would be to disable native events with the IE driver. Unfortunately, the simulated events aren't ready for normal use.

Why are Selenium IDE playback controls inactive? (How can I run recorded tests?)

I started learning how to use Selenium today. I have never used it before. I downloaded the Selenium IDE (1.0.10) plugin for FireFox (3.5.16). The way it's behaving is not matching up to the docs.
When I click the record button and perform actions in my browser, nothing happens in the IDE (nothing is recorded). (Actually, initially it did record, but now it doesn't) I tried restarting FireFox and that had no effect.
Also, the main controls are now inactive. I've included a screen shot to show what I mean by that. The controls remain inactive even it I click or double click on the name of a test case in the panel on the left.
And one final question -- it appears that a Selenium test case mentions Chrome in its default configuration even though the docs say you can only record tests using FireFox. Should I do anything about that?
If anyone can shed light on any of the above mysteries I would appreciate it. Thanks!
UPDATE
I restarted FireFox again and now it's recording actions, but the controls are still greyed-out as in the screenshot, so I can't play back the test.
The issue is that you are not in the HTML runner mode. The IDE has no concept of ruby or python or c# or Java. That is up to plugins which just essentially do a find an replace.
*chrome means Firefox Chrome. Something that has been around for a lot longer than Google Chrome the browser. It means use the browser chrome which removes a couple sandboxing issues.
If you want to play back the tests you can't go out of the table mode otherwise the IDE won't understand what to do. The code in the screenshot should be stored in a .rb file and that should be executed.
Let me try to unravel mysteries -
As soon as you launch the IDE it would be in recording mode. Do you see last Red button which is enabled.
IDE Tests can be executed only when in the selenese/html format (aka table format). I guess you have changed the format to ruby (I guess so), from Option > Format.
To be able to execute tests change it back to html from option > Format > HTML
Take my words, IDE is only and only for firefox