I have a fairly large set of Selenium tests (about 180), which have worked very well over a long period on XP and Win7 32/64bit machines.
Recently, after a Windows 7 update (which may be coincidental), the tests have become unreliable. They fail at random, but always with the same problem - an expected screen is displayed but the WaitForPageToLoad() method does not return to confirm this. This does not occur on the XP machines, only the recently updated Win7 machines.
Platform: Win7, 32 and 64bit, Selenium 1.0 and 2.33.0 (no difference in behaviour), VS2008, browser IE9.
Scenario: A test initially displays a 'restart' screen with a single button, clicks on the button which should launch a login screen (all the tests go through the same code to do this). The login screen is displayed in the browser but the test line
selenium.WaitForScreenToDisplay(30000);
does not return so the test times out with an error message. The tests will fail in this way completely at random - about half of them fail, but not consistently the same ones.
The application itself behaves perfectly when a human being interacts with the browser. The selenium logs don't give much in the way of clues - the last line is always 'waiting for page', eg "....Command request: waitForPageToLoad[30000,... ]".
Stepping through the test in the VS debugger never reproduces the problem.
The actual code where the problem manifests itself is
selenium.Open(GetRestartPageURL());
selenium.WaitForPageToLoad("30000");
selenium.Click("Button");
selenium.WaitForPageToLoad("30000"); <-- this is where it times out even though the expected screen that is launched by "Button" is now displayed in the browser
Is there a known problem, or a workaround for this? Is it an issue with IE9 and Selenium 1.0? Its come out of the blue at a critical time.
This turned out to be a bug in IE9/10 and/or selenium, or at least a bug in IE9/10 that the selenium folks do not look like addressing any time soon. I worked around it by writing my own WaitForPage method that looks at window.document.readyState in the browser and also monitors the delay so I still have a timeout.
Here's the code, if it will help anyone else:
internal static void WaitForPageToLoad(ISelenium selenium)
{
//Wait until the browser reports that it is no longer loading the page, or 'timeOut' has been reached.
//Pause 1/4 second between attempts (should normally be sufficient for the page to load, unless it is a very slow page)
const int timeOut = 30000; //mS
const int pause = 250; //mS
int timeWaited = 0;
do
{
System.Threading.Thread.Sleep(pause);
timeWaited += pause;
}
while (selenium.GetEval("window.document.readyState") != "complete" && timeWaited<timeOut);
if (timeWaited >= timeOut)
{
//abort test and notify error:
Assert.Fail("Expected page was not dislpayed");
}
}
There are two issues in the Selenium bug tracker referencing this bug: 1639 and 2451
Related
Everytime I try to access this website and open google-chrome-devtools I am unable to inspect any of the elements through the Inspector as the UI is having an overlay along with a message Paused in debugger.
The upvoted and accepted answer of this discussion says to check the Source tab, check under the Event Listener Breakpoints panel if you've set any breakpoints under 'Mouse'. I have cross checked that none of the Sources -> EventListenerBreakpoint are set.
The upvoted and accepted answer of this discussion says to check if the little octagonal stop/pause sign (at lower left of Chrome "Sources") is colored (blue or purple). I am not sure why do I need to do that additionally for selected websites.
Snapshot:
The upvoted and accepted answer of this discussion speaks about the Manual Steps.
All the solutions seem to point towards the manual process. But this issue seems to me the root cause behind Selenium being unable to getPageSource().
Code trials:
System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
options.addArguments("disable-infobars");
options.addArguments("--disable-extensions");
WebDriver driver = new ChromeDriver(options);
driver.get("http://rd.huangpuqu.sh.cn/website/html/shprd/shprd_tpxw/List/list_0.htm");
Output: Chrome opens but doesn't navigates to the url.
So my questions are:
In which case can Paused in debugger error occurs?
Is it an error from the frontend development?
How can I bypass this error during the Automated Tests through Selenium?
In which cases can the Paused in debugger error occur?
Anytime you are accessing this page with the dev tools open. The debugger; line will pause javascript execution, but browsers will ignore it if the dev tools are closed.
Is it an error from the frontend development?
In this case, no--they're deliberately trying to keep you out. The purpose of this function is to pause execution and then redirect your browser to a different page if it takes longer than 100ms to resume. I would speculate that this is designed to interfere with automated crawlers like selenium, because a regular user wouldn't be affected and a human developer can just hack around it.
How can I bypass this error during the Automated Tests through Selenium?
My first recommendation would be to try running Selenium headlessly, if that's an option. If not, use the hotkey to resume execution (F8). You can use whatever method you like for generating a keypress; with the java.awt package it will look something like this:
Robot robot = null;
try
{
robot = new Robot();
}
catch(Exception e)
{
//handle failure
}
robot.keyPress(KeyEvent.VK_F8);
Remember that you have to trigger this within 100ms, so use whatever logic you like to detect the block and respond quickly. If you just want something quick and dirty, I would just make it spam F8 keypresses every 50ms for a period of time until you're certain the page has loaded.
EDIT: On further investigation, this page is extremely messy and hostile to anyone with the dev tools open. There is not one but several functions that trigger debugger;and they get called repeatedly on a timer for as long as you're on the page. Running headlessly seems like the best choice, unless you want to continue spamming F8 for the entire session.
I’m trying to send automated text messages from Skype web client, using Selenium.
So far, I was able to authenticate myself and select the required unique recipient. It works fine both programmatically (Java bindings) and using Selenium IDE.
But I was not able to successfully add text to the message box. And without that, Skype does not even shows the send button!
In a recent past, I googled that one could send a message with something like:
input_messages = browser.find_element_by_name('messageInput')
input_messages.send_keys('Testing Output' + Keys.RETURN)
But I guess Microsoft changed the web client as this does not work anymore, namely by not showing the “Send” button unless something is written in the message box:
Using Selenium IDE, it records this set of commands (Skype authentication omitted):
However, running above script, I get what seems to be an overlapped “Test” string on top of original “Type a message”:
It seems obvious to me that Selenium IDE is not placing my “Test” string in the “right” place. And because of that, not even the send button is shown.
Here’s the “edit content” parameters:
Target
css=.notranslate
xpath=//div[2]/div[2]/div/div/div/div/div/div/div/div[2]/div/div/div/div[2]/div/div/div
Value
<div data-contents="true"><div class="" data-block="true" data-editor="f244q" data-offset-key="0-0-0"><div data-offset-key="0-0-0" class="public-DraftStyleDefault-block public-DraftStyleDefault-ltr"><span data-offset-key="0-0-0"><span data-text="true">Test</span></span></div></div></div>
And the Chrome Inspect of the message box:
So, any idea what Selenium IDE (or myself…) is doing wrong?...
What is the right locator and how to edit its content (to set my text message), making sure the send button is then shown and clickable (though a Keys.ENTER should then suffice).
Thank you in advance!
Windows 10 - 1903 (64-bit)
Google Chrome 85.0.4183.102 (Official Build) (64-bit)
Selenium IDE 3.17.0
chromedriver_win32-85.0.4183.87
selenium-server-standalone-3.141.59.jar
I have encountered similar problems and tried many methods:
clear the element before sendkeys
sendkeys multiple times in for-loop
I can’t tell which method is effective, so I will give you a code snippet in my real project.
// for the div element
boolean bl = false;
for (int i = 0; i < 3; i++) {
element.clear();
element.sendKeys(text);
if (element.getText().equals(text)) {
bl = true;
break;
}
}
When I send "Test" to a textbox the web page displays TTeesstt in the texbox.
Even though the web form displays the double characters it appears what is actually submitted to the web app is only the original text.
When I ran my test using IE 8 the text "Test" was inserted once.
When I upgraded to IE 11 the text was inserted very slowly. This problem was discussed here.
I was trying to solve the slow Sendkeys problem and was playing around with my code to programmatically use IE or Chrome. I've backed off that code to just trying to use IE directly (InternetExplorerDriver class).
I've downloaded and installed all IE 11 cumulative updates.
I saw a post in Kaspersky labs forums about the double character problem. The posts seemed to indicate the problem is related to IBM Trusteer. I do have Trusteer installed on my personal laptop. However, the problem is occurring on a remote computer. I login to the remote computer via a VPN. While not 100% sure I don't think the remote computer has Trusteer.
Environment:
Windows 7 64-bit
InternetDriverServer 3.8.0.0, 32-bit
IE 11.9600.1886IS, Updates KB4052978
Selenium
I had this problem also. I was able to fix it by adding an option to my IEDriver in my selenium code. The option to add is:
ieOptions.EnableNativeEvents = true;
Unfortunately, that slowed my text-entry to about 1 character every five seconds. I was able to fix that by adding RequireWindowFocus = true.
My constructor now contains this code:
if (DriverType.IsType<InternetExplorerDriver>())
{
var ieOptions = new InternetExplorerOptions { IgnoreZoomLevel = true,
EnableNativeEvents = true, RequireWindowFocus = true};
Driver = new InternetExplorerDriver(ieOptions);`
}
For those who has Selenium-Serenity
Thanks to Joshua I found solution to add in serenity.properties
serenity.driver.capabilities=nativeEvents:true;requireWindowFocus:true;
I am working on writing a story for a bdd framework which uses jbehave/selenium/webdriver and am having a problem where the test encounters an error while running the story but appears to be fine when running manually. I'm having a problem where javascript for the functionality I'm testing behaves slightly different when I'm running tests manually on firefox vs through selenium web driver on the same system/version of firefox and this difference is causing a js error.
I've debugged and basically the root of the problem appears to be that var request_XML_container = $('div_appendpoint_id'); returns something different when I'm running the test manually vs when I run through the bdd framework.
var request_XML_container = $('div_appendpoint_id');
request_XML_container.innerHTML = encoded_xml_from_request;
var pos = method_to_get_position('id_of_place_div_should_be_appended_to');
// JS exception is thrown saying that style is not defined **ONLY**
// when running through web driver. Running test manually on
// same system and same browser works fine.
request_XML_container.style.left = (pos[0] - 300) + 'px';
request_XML_container.style.top = (pos[1] + 25) + 'px';
request_XML_container.style.display = "block";
Why this would work fine when running manually that var request_XML_container = $('div_appendpoint_id'); would return an item with style defined, but when running through webdriver that the style attribute of the element would not be defined?
UPDATE: I had originally thought that this was updating an iframe, but I read the markup wrong and the iframe I saw is a sibling - not a parent - of the element where the response is being appended to. I'm trying to simply append the response to a div. To be honest, this only makes things more confusing as grabbing a div by id should be pretty straight forward and I'm now sure why webdriver would be producing a different return element in this situation.
UPDATE 2: Steps to reproduce and information about the system I'm on:
Use webdriver to navigate to this url: http://fiddle.jshell.net/C3VB5/11/show/
Have webdriver click the button. It should not work
Run your test again, but pause put a breakpoint at your code to click the driver
Click the button on the browser that webdriver opened. It should not work
Refresh the browser page on the browser that webdriver opened. Now, it should work.
System details:
OS : OS X 10.8.5 (12F37)
IDE : Eclipse Kepler: Build id: 20130614-0229
Browser (used manually and by webdriver) : Firefox 23.0.1
Selenium version: 2.35.0
UPDATE 3: I have provided this maven project on github to aid in reproducing: https://github.com/dkwestbr/WebdriverBug/tree/master/Webdriver
Synopsis/tl:dr; Basically, in certain situations it appears as though webdriver is overwriting the '$()' javascript method with a method that does not return an HTMLElement with innerHTML or style defined (among other things). This post details the issue and how to reproduce.
I have opened this ticket to track the issue: https://code.google.com/p/selenium/issues/detail?id=6287&thanks=6287&ts=1379519170
I have confirmed that this is a bug with the Thucydides framework (understandable since they still aren't at a 1.0 release).
Issue can be tracked here: https://java.net/jira/browse/THUCYDIDES-203
For reliability testing, we are testing our web application through selenium automated tests runs on infinite loop on the Firefox /IE browser. Can some one have an idea on how to track when browser crashes/ hung up with out exiting/stopping the test run?
i guess it could be done this way,
if the browser crashes : as there will not be any window opened, you will get an error
generated in javascript for further commands which you send and that will be sent to the
client code.
example :
try to close the window which is already closed or not existed and you will get an exception / error and catch this in the code. (java code example) :
try {
selenium.close(); //if it is a main window
} catch(SeleniumException se) {
if(!se.getMessage().equals("Current window or frame is closed!"))
//do what ever you want here
}
as i said this is to give you some idea about how to go a head and may not be exactly what
you are looking for.
but i have a logic done in this way to close the entire application (multi window)
window by window and it works fine