Infinite wait encountered in Selenium Webdriver

676 views
Skip to first unread message

Amrita Basu

unread,
Jun 2, 2016, 11:18:47 PM6/2/16
to Selenium Users
My test scenario is this :

I ask Selenium to :

1. Launch a website.

2. Click on the " Sign in using Google " button.The Google sign-in window opens .

3. Switch focus to the newly opened window, enter valid credentials and hit Sign In(At this point , the sign-in window closes and my profile page loads on the website in my parent window )

4. Click something on the profile page

Now , I deliberately didn't switch focus back to my parent window before doing Step 4 and since Webdriver still had its focus set on the (now closed) sign-in window,I expected a NoSuchElementException . But instead , it went on an endless wait mode after executing step 3 and never got to Step 4 . Can anyone please explain this to me ? Thanks in advance !

⇜Krishnan Mahadevan⇝

unread,
Jun 3, 2016, 1:04:40 AM6/3/16
to Selenium Users
PS : This is a really long post.. so please feel free to skip

Amrita,
This was a really interesting question.. :)

Although I am not sure if what I am explaining is actually the fact, I still would like to call out what I have understood and maybe someone more educated on the selenium internals will perhaps chime in and correct me.

When you create a new WebDriver object, Selenium creates a httpclient. This is what selenium uses to talk to the server component and thus interact with the web browser. So in the case of firefox its the plugin that is the server, for chrome its chromedriver and for IE its IEDriverServer binary.

Selenium always assumes a value of 2 minutes as connection timeout and a value of 3 hours as socket timeout when it creates the http client [ 1 http client gets created for every webdriver instantiation ]. For more information on connection timeout and socket timeouts please see this SO post : http://stackoverflow.com/a/7360916/679824

To simulate your problem in a much more simpler fashion, I wrote up a small piece of code.

public class Interesting {
public static void main(String[] args) {
RemoteWebDriver driver = null;
try {
ChromeDriverService service = new ChromeDriverService.Builder().withVerbose(true).build();
driver = new ChromeDriver(service);
driver.get("http://the-internet.herokuapp.com/checkboxes");
WebElement element = driver.findElement(By.id("checkboxes"));
} finally {
if (driver != null) {
driver.quit();
}
}
}

}
I then ran the above piece of code in debug mode with a breakpoint set at the line 
WebElement element = driver.findElement(By.id("checkboxes"));
At this point, I would click on open a new tab in the chrome browser that Selenium spawned for me, close off the origin page [viz the internet.herokuapp.com/checkboxes page ] and resume the execution of the code.
I was able to simulate your issue.
But in my case I was not stalling for ever. The chromedriver (the server component here) waited for a max of 10 minutes before it gave up saying that it didn't get any response from the renderer.

Here's how the logs looked like

[7.283][INFO]: Done waiting for pending navigations
[7.283][INFO]: RESPONSE Navigate
[18.408][INFO]: COMMAND FindElement {
   "using": "id",
   "value": "checkboxes"
}
[18.409][DEBUG]: DEVTOOLS COMMAND Console.enable (id=15) {

}
[18.409][DEBUG]: DEVTOOLS COMMAND DOM.getDocument (id=16) {

}
[18.409][DEBUG]: DEVTOOLS COMMAND Runtime.enable (id=17) {

}
[18.409][DEBUG]: DEVTOOLS COMMAND Page.enable (id=18) {

}
[18.409][DEBUG]: DEVTOOLS COMMAND Page.enable (id=19) {

}
[942:57611:0603/101113:ERROR:devtools_http_handler.cc(387)] GetMimeType doesn't know mime type for: page/F5FF0621-F890-4360-88A3-A949D6A14264 text/plain will be returned
[942:1295:0603/101113:ERROR:devtools_http_handler.cc(387)] GetMimeType doesn't know mime type for: page/F5FF0621-F890-4360-88A3-A949D6A14264 text/plain will be returned
[618.413][SEVERE]: Timed out receiving message from renderer: 600.000
[618.455][INFO]: RESPONSE FindElement timeout: Timed out receiving message from renderer: 600.000
  (Session info: chrome=50.0.2661.102)
[618.494][INFO]: COMMAND Quit {

}
[618.548][INFO]: RESPONSE Quit
[618.548][DEBUG]: Log type 'driver' lost 1 entries on destruction
[618.548][DEBUG]: Log type 'browser' lost 0 entries on destruction
Exception in thread "main" org.openqa.selenium.TimeoutException: timeout: Timed out receiving message from renderer: 600.000
  (Session info: chrome=50.0.2661.102)
  (Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Mac OS X 10.11.5 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 600.03 seconds
Build info: version: '2.53.0', revision: '35ae25b1534ae328c771e0856c93e187490ca824', time: '2016-03-15 10:43:46'


So I don't think you will be stalling endlessly. The server component would be having a timeout mechanism after which it defaults to timing out.

Even if the server component didn't have this timeout logic defined, the client (which is your test case) is going to time out in 3 hours with a socket timeout exception, because for 3 hours if there is no data that flows in your already established connection, the http client library (which selenium uses) will trigger a socket timeout exception (which in our case, selenium defines it as a value of 3 hours). See org.openqa.selenium.remote.internal.HttpClientFactory#createHttpClient(org.apache.http.auth.Credentials)

Now for the last important part of your question... Why does webdriver behave in this way ? When the original page with which it was interacting, isn't there any more shouldn't it throw an error immediately [ Similar to how selenium throws a NoSuchElementException on a page if you tried to look for a non existent element ]..! Well technically it should, but in this case, the page with which it was interacting, wasn't closed by selenium, but something outside of selenium's knowledge. So for Selenium it still thinks that the page is there and is perhaps still being loaded [ Maybe.. or may not be ].

That perhaps explains why you are seeing this behavior.

All said and done, I myself ain't convinced that I did answer your question, but yeah it did get me started on trying to figure out what goes on behind the scenes.

I hope someone from the Selenium Dev community (or) someone much more educated on Selenium than me, would chime in and answer that last part or maybe completely correct my answer !!

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/62f6d260-7f5c-411a-9a84-1975aa93e741%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages