Issues with HtmlUnitDriver (others work great!!)

412 views
Skip to first unread message

CodeMonkey

unread,
Feb 10, 2010, 11:31:13 AM2/10/10
to webdriver
Hey Gang,

I recently upgraded from Selenium 1.2 to Selenium 2.0. So far things
are going good. I can run my tests in FireFox and IE; however, I want
to get better performance by using the HtmlUnitDriver. Running the
very first sample code (google search example) I get the following
error. Any ideas?

Exception in thread "main" org.openqa.selenium.NoSuchElementException:
Cannot find element with name: q
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1',
java.version: '1.5.0_22'
Driver info: driver.version: htmlunit
at
org.openqa.selenium.htmlunit.HtmlUnitDriver.findElementByName(HtmlUnitDriver.java:
545)
at org.openqa.selenium.By$4.findElement(By.java:148)
at
org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:
279)
at MainTest.main(MainTest.java:22)

Thanks,

CodeMonkey

Daniel Wagner-Hall

unread,
Feb 10, 2010, 12:22:57 PM2/10/10
to webd...@googlegroups.com
Could you send the test case you are executing? (Java code)

> --
> You received this message because you are subscribed to the Google Groups "webdriver" group.
> To post to this group, send email to webd...@googlegroups.com.
> To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.
>
>

CodeMonkey

unread,
Feb 10, 2010, 12:33:32 PM2/10/10
to webdriver
It is literally the same example on the Selenium 2.0 "The 5 Minute
Getting Started Guide":

[code]
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;

public class MainTest {
public static void main(String[] args) {
// Create a new instance of the html unit driver
// Notice that the remainder of the code relies on the
interface,
// not the implementation.
WebDriver driver = new HtmlUnitDriver();

// And now use this to visit Google
driver.get("http://www.google.com");

// Find the text input element by its name
WebElement element = driver.findElement(By.name("q"));

// Enter something to search for
element.sendKeys("Cheese!");

// Now submit the form. WebDriver will find the form for us
from the element
element.submit();

// Check the title of the page
System.out.println("Page title is: " + driver.getTitle());
}
}
[/code]


On Feb 10, 12:22 pm, Daniel Wagner-Hall <dawag...@gmail.com> wrote:
> Could you send the test case you are executing? (Java code)
>

Eran M.

unread,
Feb 10, 2010, 1:10:08 PM2/10/10
to webd...@googlegroups.com
The same example works fine for me. It's possible (but sounds unlikely) that HtmlUnit has not finished rendering the page when the call to findElement is executed.
Could you get the page source and see if it looks reasonable? (e.g. the same source you'd get by navigating to www.google.com yourself and viewing the source).

Eran

CodeMonkey

unread,
Feb 10, 2010, 2:04:48 PM2/10/10
to webdriver
In the source for www.google.com we have:
<input autocomplete="off" onblur="google&&google.fade&&google.fade()"
maxlength=2048 name=q size=55 class=lst title="Google Search"
value="">

So, as you can see an element with the name 'q' is present.

One thing I want to point out is if I take the sample code and replace
[WebDriver driver = new HtmlUnitDriver();] with [WebDriver driver =
new FirefoxDriver()] or [WebDriver driver = new
InternetExplorerDriver();] it will work.

Hypothetically shouldn't all drivers work the same? Am I missing any
additional setup for the HtmlUnitDriver?

On Feb 10, 1:10 pm, "Eran M." <eran....@gmail.com> wrote:
> The same example works fine for me. It's possible (but sounds unlikely) that
> HtmlUnit has not finished rendering the page when the call to findElement is
> executed.
> Could you get the page source and see if it looks reasonable? (e.g. the same

> source you'd get by navigating towww.google.comyourself and viewing the
> source).
>
> Eran

> > org.openqa.selenium.htmlunit.HtmlUnitDriver.findElementByName(HtmlUnitDrive­r.java:


> > > > 545)
> > > >        at org.openqa.selenium.By$4.findElement(By.java:148)
> > > >        at
>
> > org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java­:
> > > > 279)
> > > >        at MainTest.main(MainTest.java:22)
>
> > > > Thanks,
>
> > > > CodeMonkey
>
> > > > --
> > > > You received this message because you are subscribed to the Google
> > Groups "webdriver" group.
> > > > To post to this group, send email to webd...@googlegroups.com.
> > > > To unsubscribe from this group, send email to

> > webdriver+...@googlegroups.com<webdriver%2Bunsubscribe@googlegroups­.com>


> > .
> > > > For more options, visit this group athttp://
> > groups.google.com/group/webdriver?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "webdriver" group.
> > To post to this group, send email to webd...@googlegroups.com.
> > To unsubscribe from this group, send email to

> > webdriver+...@googlegroups.com<webdriver%2Bunsubscribe@googlegroups­.com>


> > .
> > For more options, visit this group at

> >http://groups.google.com/group/webdriver?hl=en.- Hide quoted text -
>
> - Show quoted text -

Ahmed Ashour

unread,
Feb 10, 2010, 3:39:04 PM2/10/10
to webd...@googlegroups.com
Hi,
 
From which country do you test? As I remember google.com points to google.com.<country_code>, with a known different issue for Right-To-Left languages.
 
Yours,
Ahmed
----
Blog: http://asashour.blogspot.com

From: CodeMonkey <chrisca...@gmail.com>
To: webdriver <webd...@googlegroups.com>
Sent: Wed, February 10, 2010 10:04:48 PM
Subject: [webdriver] Re: Issues with HtmlUnitDriver (others work great!!)

Marc Guillemot

unread,
Feb 11, 2010, 2:46:43 AM2/11/10
to webd...@googlegroups.com
Hi,

HtmlUnitDriver default is to have JavaScript disabled therefore you
can't just replace "new XXXDriver" by "new HtmlUnitDriver".

Personally I think that it is a very bad idea. In fact there are two
things that I dislike in the HtmlUnitDriver constructor:
- I think that JavaScript should be enabled by default
- I think that there shouldn't be a default constructor, but only
constructors where you explicitly specify the browser to simulate
(default is IE7 currently).

I've already tried to convince Simon to change that but without luck so
far :-(

Cheers,
Marc.
--
Blog: http://mguillem.wordpress.com

Simon Stewart

unread,
Feb 13, 2010, 4:30:26 PM2/13/10
to webd...@googlegroups.com
That's because Simon is waiting until he can run tests using the
HtmlUnitDriver on a GWT application without it causing trouble. The
new HtmlUnit 2.7 release looks promising :) I'm looking forward to
trying out my test cases with it again.

As for the default constructor, although I can see your point, I
disagree. Users of the HtmlUnitDriver fall into two camps: those who
know what they're doing will be calling a specific constructor. Those
who don't care, but just want a lightweight alternative to a full
browser will just pick any value. We should make it easy for users who
know what they're doing to Do The Right Thing, and for users who don't
care, we should be providing a sensible default via the no-arg
constructor.

Cheers,

Simon

> webdriver+...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages