I'm having intermittent problems using getTitle with WebDriver 2.21.0; a test that does1. findElement( an <a href ...> link ).click(),2. assert that driver.getTitle() looks as expectedsometimes fails, and sometimes passes. In the failing cases, .getTitle() returns "". The page it is called on is static, i.e. there isn't any JavaScript magic that updates the page's title after the page has been loaded.I found an existing bug report for this: http://code.google.com/p/selenium/issues/detail?id=3543... but that was just closed with "WorkingAsIntended". I've protested this, but thought I'd also bring the issues up here, in the hope that someone might help me understand how things ought to work.At the moment, I'm having a hard time understanding the following things:1. WebElement.click() is documented as a method that "will attempt to block until the page has loaded" -- which does not match the suggestion given on the bug to use a WebDriverWait to ensure that the page has loaded before .getTitle will work.2. The documentation for WebDriver.getTitle says that it should return null "if [a title] is not already set". As mentioned above, I'm seeing the empty string rather than null in the failing cases. Is there some intentional difference between returning "" and null? Is the documentation or the current implementation buggy?
The symptoms would suggest that the page is not fully loaded when you are getting the title. As a result I would suggest you set an explicit wait to ensure that the page has loaded before trying to get the title.
I would point out that is says that WebDriver will *attempt* to block until the page has loaded. It’s very hard (read almost impossible) to be 100% sure that a page has loaded unless you put in an explicit wait that checks for something on the page that is known to only be displayed once the page has finished loading.
Assuming this is a valid problem:
· Do you have a minimal test case that can regularly reproduce this behaviour?
· Does this happen in all browsers (It’s possible the browser you are using is creating a <title> element and then populating it afterwards and WebDriver is getting the title text before the browser has finished rendering the <title> element in the DOM correctly)?
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/xILlo0mJ20kJ.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en-US.
The symptoms would suggest that the page is not fully loaded when you are getting the title. As a result I would suggest you set an explicit wait to ensure that the page has loaded before trying to get the title.
I would point out that is says that WebDriver will *attempt* to block until the page has loaded. It’s very hard (read almost impossible) to be 100% sure that a page has loaded unless you put in an explicit wait that checks for something on the page that is known to only be displayed once the page has finished loading.
Assuming this is a valid problem:
· Do you have a minimal test case that can regularly reproduce this behaviour?
· Does this happen in all browsers (It’s possible the browser you are using is creating a <title> element and then populating it afterwards and WebDriver is getting the title text before the browser has finished rendering the <title> element in the DOM correctly)?
From: seleniu...@googlegroups.com [mailto:seleniu...@googlegroups.com] On Behalf Of Harald Meland
Sent: 28 June 2012 11:45
To: seleniu...@googlegroups.com
Subject: Re: [selenium-users] Re: getTitle intermittently does not return title
On Thursday, 28 June 2012 12:11:33 UTC+2, Mark Collin wrote:
The symptoms would suggest that the page is not fully loaded when you are getting the title. As a result I would suggest you set an explicit wait to ensure that the page has loaded before trying to get the title.
That is exactly what was suggested on the bug report I mentioned... but I'd really like to know a bit more about when I can/can't trust WebDriver's heuristic for determining whether a page has loaded. If I just go with your suggestion without having obtained this knowledge first, I suspect that I would make my tests significantly less readable by adding lots and lots of redundant explicit waits.
You will need somebody who knows exactly how that piece of code works to explain that to you, or you can check out the code base and investigate for yourself.
I would point out that is says that WebDriver will *attempt* to block until the page has loaded. It’s very hard (read almost impossible) to be 100% sure that a page has loaded unless you put in an explicit wait that checks for something on the page that is known to only be displayed once the page has finished loading.
I read the documentation as saying, in practice: WebDriver will wait until the full (static) HTML of the page has been loaded; any dynamic content modifications that might be performed by JavaScript is not ensured to be complete, and will have to be waited for.
Hence my surprise that a static <title> tag in the HTML of my page did not always result in a non-empty return value from .getTitle.
If my reading of the documentation is incorrect, then what value does the *attempt* to block until the page has loaded really have? If I'll have to *always* insert some explicit wait after .click()ing to make sure that my tests are reliably on a fully loaded page, then the utility of .click() doing an *attempt* to ensure this is ... rather small, I'd say.
I would expect a static page to not cause any problems, usually timing problems are due to JavaScript either not finishing processing before WebDriver starts doing things with the page, or JavaScript changing things unexpectedly after WebDriver has started doing things with the page.
Assuming this is a valid problem:
· Do you have a minimal test case that can regularly reproduce this behaviour?
The test case itself is rather small, but it's running against a non-publicly available web application.
Can you reproduce it on a publically available applications, or anonymise the HTML of the page that is giving you a problem and make it available publically?
· Does this happen in all browsers (It’s possible the browser you are using is creating a <title> element and then populating it afterwards and WebDriver is getting the title text before the browser has finished rendering the <title> element in the DOM correctly)?
I've just tried with Firefox, and it appears that the problem is much more prevalent in older Firefox versions (I get failures ~50% of the time on Firefox 3) than in newer versions (I've so far seen a single failure on Firefox 10, and a colleague saw a single failure in Firefox 13; repeatedly running with Firefox 13 on my laptop has so far not managed to reproduce the failure there).
· What about other browsers, is this a FireFox only problem?
· What are the machine specs?
· Are the problems only seen on less powerful machines?
The symptoms seem to indicate that WebDriver is starting checks against the title before the Browser has finished rendering the DOM.
This thread will probably be interesting reading for you:
https://groups.google.com/d/topic/selenium-developers/cZbJ6oX9S9s/discussion
--
Harald
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/mcVdoAlWt1AJ.
I'd be curious what happens if you use:WebElement titleTag = waitForElement(By.tagName("title"));String title = titleTag.getText();
The code for waitForElement can be found at http://darrellgrainger.blogspot.ca/2012/01/waitforelement.html.
It does seem like the getTitle() has some sort of problem. If it could not find the TITLE tag I'd expect a NoSuchElementException.
The other option is write a hack to work around the problem but make the hack so it will still work when the getTitle() method works as expected. You could wrap the getTitle() method to be:
I would expect a static page to not cause any problems, usually timing problems are due to JavaScript either not finishing processing before WebDriver starts doing things with the page, or JavaScript changing things unexpectedly after WebDriver has started doing things with the page.
Can you reproduce it on a publically available applications, or anonymise the HTML of the page that is giving you a problem and make it available publically?
· What are the machine specs?
· Are the problems only seen on less powerful machines?
This thread will probably be interesting reading for you:
https://groups.google.com/d/topic/selenium-developers/cZbJ6oX9S9s/discussion
I haven’t looked at the code that works out that the page has finished loading so this is guesswork, but it would seem that WebDriver is starting to process the page when the jQuery(document).ready event is thrown rather than waiting for the JavaScript that is processed after the jQuery JavaScript to finish..
From: seleniu...@googlegroups.com [mailto:seleniu...@googlegroups.com] On Behalf Of Harald Meland
Sent: 29 June 2012 13:02
To: seleniu...@googlegroups.com
Subject: Re: [selenium-users] Re: getTitle intermittently does not return title
On Thursday, 28 June 2012 13:13:54 UTC+2, Mark Collin wrote:
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/cE6xor4l05QJ.
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.titleIs("your anticipated page title"));