C# HTMLUnit

2,059 views
Skip to first unread message

ninjairose

unread,
Mar 2, 2011, 12:48:08 PM3/2/11
to webdriver
I want to create tests in C# using htmlunit.
My biggest problem comes from logging into accounts.
When i go to log in, a new window pops up.
I have it working with firefox using:


//login
driver.FindElement(By.LinkText("My Profile")).Click();

foreach (string handle in driver.GetWindowHandles())
{
driver.SwitchTo().Window(handle);
}

driver.FindElement(By.Id("email"));

but if i do this with htmlunit, it says it can not find ID email.

The way i'm trying to log in is through facebook connect API.

has anyone done this or have any ideas?

Thank you!

QA_manager

unread,
Mar 4, 2011, 8:50:46 AM3/4/11
to webdriver
What version of Webdriver are you using?
Message has been deleted

Kathleen Jacobs

unread,
Mar 4, 2011, 11:52:14 AM3/4/11
to webd...@googlegroups.com

2.0b2

On Mar 4, 2011 8:50 AM, "QA_manager" <no_ca...@yahoo.com> wrote:

What version of Webdriver are you using?


On Mar 2, 12:48 pm, ninjairose <katidjac...@gmail.com> wrote:

> I want to create tests in C# using ...

ninjairose

unread,
Mar 7, 2011, 10:06:45 AM3/7/11
to webdriver
Has anyone been able to do this?

On Mar 4, 11:52 am, Kathleen Jacobs <katidjac...@gmail.com> wrote:
> 2.0b2
>

Jim Evans

unread,
Mar 7, 2011, 1:38:59 PM3/7/11
to webdriver
First, I'm assuming you're using HtmlUnit via the RemoteWebDriver,
since there is no supported direct binding for .NET. If so, this means
that similar code would fail in other languages, and it's not a
problem related directly to the .NET bindings.

Second, your C# code, as written, is likely to be unreliable. You are
cycling through every window in the list of window handles using the
foreach construct, and hoping that the correct window will be the last
one in the list. Here is something that will work using the
methodology you've chosen (completely untested code):

IWebElement element = null;
// save the current window handle so we
// can switch back when we are done with
// the popup.
string originalHandle = driver.GetWindowHandle();
driver.FindElement(By.LinkText("My Profile")).Click();

foreach(string handle in driver.GetWindowHandles())
{
driver.SwitchTo().Window(handle);
try
{
element = driver.FindElement(By.Id("email"));
break;

}
catch(NoSuchElementException)
{
}
}

if (element == null)
{
// didn't find the element, so handle the error case.
}
element.SendKeys("mye...@example.com");

Now, this will likely work, but it's a poor window location strategy.
You're better off if you know the name of the popup window.
Alternatively, you could skip the current window handle in your
foreach loop.

Hope this helps,
--Jim

Kathleen Jacobs

unread,
Mar 7, 2011, 3:09:52 PM3/7/11
to webd...@googlegroups.com
I am using HtmlUnit with RemoteWebDriver.
I tried using the code idea you gave me with choosing the window with the ID email.
It works fine if i run it with a firefox driver but once i switch to htmlunit it does not work.  It tells me its unable to find the element email.

Here is my code:


using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using NUnit.Framework;
using OpenQA.Selenium.Firefox;

namespace HTMLUnit
{

    [TestFixture]
    public class HTMLUnitTesting
    {
        [Test]
        public void Main()
        {

            ICapabilities desiredCapabilities = DesiredCapabilities.HtmlUnit();
            IWebDriver driver = new RemoteWebDriver(desiredCapabilities);
           

            driver.Navigate().GoToUrl("http://games.tlc.discovery.com/");

            //Login
            IWebElement element = null;
            string originalHandle = driver.GetWindowHandle();


            //login
            driver.FindElement(By.LinkText("My Profile")).Click();

            foreach (string handle in driver.GetWindowHandles())

            {
                driver.SwitchTo().Window(handle);
                try
                {
                    element = driver.FindElement(By.Id("email"));
                    break;

                }
                catch (NoSuchElementException)
                {
                }
            }
            if (element == null)
            {
                // didn't find the element, so handle the error case.
            }
            element.SendKeys("em...@gmail.com");

            driver.FindElement(By.Id("pass")).SendKeys("password");

            driver.FindElement(By.Name("login")).Click();

            driver.SwitchTo().Window(originalHandle);
}

--
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.


Jim Evans

unread,
Mar 7, 2011, 8:05:35 PM3/7/11
to webdriver
I dislike passing the buck on something like this, but it could be an
issue with HtmlUnit itself. I'm not sure how to go about checking that
though, since I'm not much of a Java developer.
> > element.SendKeys("myem...@example.com");

Ivo Grootjes

unread,
Mar 29, 2011, 10:10:58 AM3/29/11
to webdriver
Can it have something to do with the popup opening a https url?

What''s the value of driver.PageSource for the windows u loop through?

On Mar 8, 3:05 am, Jim Evans <james.h.evans...@gmail.com> wrote:
> I dislike passing the buck on something like this, but it could be an
> issue with HtmlUnit itself. I'm not sure how to go about checking that
> though, since I'm not much of a Java developer.
>

ninjairose

unread,
Mar 29, 2011, 12:55:47 PM3/29/11
to webdriver
I'm trying very basic code now
where i get the following error: (the error says line 37 , right when
"IWebElement element = driver.FindElement(By.Name("q"));" triggers)

PCH.HTML.Main:
System.NullReferenceException : Object reference not set to an
instance of an object.


Code:
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using NUnit.Framework;
using Selenium;

namespace PCH
{
[TestFixture]
public class HTML
{
IWebDriver driver;


[SetUp]
public void SetupTest()
{
DesiredCapabilities capabilities =
DesiredCapabilities.HtmlUnit();
capabilities.IsJavaScriptEnabled = true;

IWebDriver driver = new RemoteWebDriver(capabilities);


driver.Navigate().GoToUrl("http://google.ca/");
}



[Test]
public void Main()
{

//The rest of the code should look very similar to the
Java library
IWebElement element =
driver.FindElement(By.Name("q"));
element.SendKeys("Cheese!");
element.Submit();
System.Console.WriteLine("Page title is: " +
driver.Title);
driver.Quit();
System.Console.ReadLine();

Ivo Grootjes

unread,
Mar 30, 2011, 4:42:50 AM3/30/11
to webdriver
Are you using beta 2 or beta 3? A stacktrace and serverlog would help
here.

Kathleen Jacobs

unread,
Mar 30, 2011, 1:19:34 PM3/30/11
to webd...@googlegroups.com
Tried this code but it looks like when it runs, it's not clicking buttons.


Code:
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using NUnit.Framework;
using Selenium;
using System;

namespace PCH
{
    [TestFixture]
    public class HTMLUnit
    {
        [Test]
        public void Main()
        {
            DesiredCapabilities desiredCapabilities = DesiredCapabilities.HtmlUnit();

            IWebDriver driver = new RemoteWebDriver(desiredCapabilities);
            desiredCapabilities.IsJavaScriptEnabled = true;
            driver.Navigate().GoToUrl("http://www.pchgames.com/RedeemTokens.aspx");
           
           
            driver.FindElement(By.ClassName("PopUp_close")).Click();

            System.Console.WriteLine("Page title is: " + driver.Title);


            IWebElement element = driver.FindElement(By.XPath("//*[@id='divHeader']/div[1]/a[5]"));
            element.Click();
           
            driver.Manage().Timeouts().ImplicitlyWait(System.TimeSpan.FromSeconds(10));
            driver.FindElement(By.Id("tab_Home"));

            System.Console.WriteLine("Page title is: " + driver.Title);
        }
    }
}


Error:
PCH.HTMLUnit.Main:
OpenQA.Selenium.NoSuchElementException : Unable to locate element with ID: tab_Home
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0_22'
Driver info: driver.version: EventFiringWebDriver


ServerLog:
13:17:47.140 INFO - Executing: [new session: {platform=ANY, javascriptEnabled=fa
lse, browserName=htmlunit, version=}] at URL: /session)
13:17:47.843 INFO - Done: /session
13:17:47.843 INFO - Executing: org.openqa.selenium.remote.server.handler.GetSess
ionCapabilities@7244ca at URL: /session/1301505458797)
13:17:47.843 INFO - Done: /session/1301505458797
13:17:47.843 INFO - Executing: [get: http://www.pchgames.com/RedeemTokens.aspx]
at URL: /session/1301505458797/url)
13:17:50.484 INFO - Done: /session/1301505458797/url
13:17:50.484 INFO - Executing: [find element: By.className: PopUp_close at URL:
/session/1301505458797/element)
13:17:50.593 INFO - Done: /session/1301505458797/element
13:17:50.609 INFO - Executing: [click: 0 org.openqa.selenium.support.events.Even
tFiringWebDriver$EventFiringRenderedWebElement@2cbc86] at URL: /session/13015054
58797/element/0/click)
13:17:50.609 INFO - Done: /session/1301505458797/element/0/click
13:17:50.609 INFO - Executing: [get title] at URL: /session/1301505458797/title)

13:17:52.250 WARN - CSS error: null [256:21] Error in expression. Invalid token
"=". Was expecting one of: <S>, <COMMA>, "/", <PLUS>, "-", <HASH>, <STRING>, ")"
, <URI>, "inherit", <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGTH
_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_MS
>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <DIMENSION>, <PERCENTAGE>, <NUMBER>, <FUNCTI
ON>, <IDENT>.
13:17:52.250 WARN - CSS error: null [256:26] Error in style rule. Invalid token
"\r\n". Was expecting one of: "}", ";".
13:17:52.250 WARN - CSS warning: null [256:26] Ignoring the following declaratio
ns in this rule.
13:17:52.359 WARN - CSS error: null [3382:21] Error in expression. Invalid token
 "=". Was expecting one of: <S>, <COMMA>, "/", <PLUS>, "-", <HASH>, <STRING>, ")
", <URI>, "inherit", <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGT
H_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_M
S>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <DIMENSION>, <PERCENTAGE>, <NUMBER>, <FUNCT
ION>, <IDENT>.
13:17:52.359 WARN - CSS error: null [3382:26] Error in style rule. Invalid token
 "\r\n". Was expecting one of: "}", ";".
13:17:52.359 WARN - CSS warning: null [3382:26] Ignoring the following declarati
ons in this rule.
13:17:52.390 WARN - CSS error: null [4667:15] Error in style rule. Invalid token
 ":". Was expecting one of: <S>, "}", <COMMA>, ";", "/", <PLUS>, "-", <HASH>, <S
TRING>, <URI>, "!", "inherit", <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_M
M>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD
>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <DIMENSION>, <PERCENTAGE>, <NUMBE
R>, <FUNCTION>, <IDENT>.
13:17:52.390 WARN - CSS warning: null [4667:15] Ignoring the following declarati
ons in this rule.
13:17:52.390 WARN - CSS error: null [4676:15] Error in style rule. Invalid token
 ":". Was expecting one of: <S>, "}", <COMMA>, ";", "/", <PLUS>, "-", <HASH>, <S
TRING>, <URI>, "!", "inherit", <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_M
M>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD
>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <DIMENSION>, <PERCENTAGE>, <NUMBE
R>, <FUNCTION>, <IDENT>.
13:17:52.390 WARN - CSS warning: null [4676:15] Ignoring the following declarati
ons in this rule.
13:17:52.390 WARN - CSS error: null [4683:15] Error in style rule. Invalid token
 ":". Was expecting one of: <S>, "}", <COMMA>, ";", "/", <PLUS>, "-", <HASH>, <S
TRING>, <URI>, "!", "inherit", <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_M
M>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD
>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <DIMENSION>, <PERCENTAGE>, <NUMBE
R>, <FUNCTION>, <IDENT>.
13:17:52.390 WARN - CSS warning: null [4683:15] Ignoring the following declarati
ons in this rule.
13:17:52.390 WARN - CSS error: null [4728:15] Error in style rule. Invalid token
 ":". Was expecting one of: <S>, "}", <COMMA>, ";", "/", <PLUS>, "-", <HASH>, <S
TRING>, <URI>, "!", "inherit", <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_M
M>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD
>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <DIMENSION>, <PERCENTAGE>, <NUMBE
R>, <FUNCTION>, <IDENT>.
13:17:52.390 WARN - CSS warning: null [4728:15] Ignoring the following declarati
ons in this rule.
13:17:52.390 WARN - CSS error: null [4734:15] Error in style rule. Invalid token
 ":". Was expecting one of: <S>, "}", <COMMA>, ";", "/", <PLUS>, "-", <HASH>, <S
TRING>, <URI>, "!", "inherit", <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_M
M>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD
>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <DIMENSION>, <PERCENTAGE>, <NUMBE
R>, <FUNCTION>, <IDENT>.
13:17:52.390 WARN - CSS warning: null [4734:15] Ignoring the following declarati
ons in this rule.
13:17:52.390 WARN - CSS error: null [4740:15] Error in style rule. Invalid token
 ":". Was expecting one of: <S>, "}", <COMMA>, ";", "/", <PLUS>, "-", <HASH>, <S
TRING>, <URI>, "!", "inherit", <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_M
M>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD
>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <DIMENSION>, <PERCENTAGE>, <NUMBE
R>, <FUNCTION>, <IDENT>.
13:17:52.390 WARN - CSS warning: null [4740:15] Ignoring the following declarati
ons in this rule.
13:17:52.390 WARN - CSS error: null [4746:15] Error in style rule. Invalid token
 ":". Was expecting one of: <S>, "}", <COMMA>, ";", "/", <PLUS>, "-", <HASH>, <S
TRING>, <URI>, "!", "inherit", <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_M
M>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD
>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <DIMENSION>, <PERCENTAGE>, <NUMBE
R>, <FUNCTION>, <IDENT>.
13:17:52.390 WARN - CSS warning: null [4746:15] Ignoring the following declarati
ons in this rule.
13:17:52.390 WARN - CSS error: null [4753:15] Error in style rule. Invalid token
 ":". Was expecting one of: <S>, "}", <COMMA>, ";", "/", <PLUS>, "-", <HASH>, <S
TRING>, <URI>, "!", "inherit", <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_M
M>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD
>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <DIMENSION>, <PERCENTAGE>, <NUMBE
R>, <FUNCTION>, <IDENT>.
13:17:52.390 WARN - CSS warning: null [4753:15] Ignoring the following declarati
ons in this rule.
13:17:52.390 WARN - CSS error: null [4759:15] Error in style rule. Invalid token
 ":". Was expecting one of: <S>, "}", <COMMA>, ";", "/", <PLUS>, "-", <HASH>, <S
TRING>, <URI>, "!", "inherit", <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_M
M>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD
>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <DIMENSION>, <PERCENTAGE>, <NUMBE
R>, <FUNCTION>, <IDENT>.
13:17:52.390 WARN - CSS warning: null [4759:15] Ignoring the following declarati
ons in this rule.
13:17:52.390 WARN - CSS error: null [4766:15] Error in style rule. Invalid token
 ":". Was expecting one of: <S>, "}", <COMMA>, ";", "/", <PLUS>, "-", <HASH>, <S
TRING>, <URI>, "!", "inherit", <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_M
M>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD
>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <DIMENSION>, <PERCENTAGE>, <NUMBE
R>, <FUNCTION>, <IDENT>.
13:17:52.390 WARN - CSS warning: null [4766:15] Ignoring the following declarati
ons in this rule.
13:17:52.390 WARN - CSS error: null [4773:15] Error in style rule. Invalid token
 ":". Was expecting one of: <S>, "}", <COMMA>, ";", "/", <PLUS>, "-", <HASH>, <S
TRING>, <URI>, "!", "inherit", <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_M
M>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD
>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <DIMENSION>, <PERCENTAGE>, <NUMBE
R>, <FUNCTION>, <IDENT>.
13:17:52.390 WARN - CSS warning: null [4773:15] Ignoring the following declarati
ons in this rule.
13:17:52.390 WARN - CSS error: null [4778:15] Error in style rule. Invalid token
 ":". Was expecting one of: <S>, "}", <COMMA>, ";", "/", <PLUS>, "-", <HASH>, <S
TRING>, <URI>, "!", "inherit", <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_M
M>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD
>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <DIMENSION>, <PERCENTAGE>, <NUMBE
R>, <FUNCTION>, <IDENT>.
13:17:52.390 WARN - CSS warning: null [4778:15] Ignoring the following declarati
ons in this rule.
13:17:52.390 WARN - CSS error: null [4813:21] Error in expression. Invalid token
 "=". Was expecting one of: <S>, <COMMA>, "/", <PLUS>, "-", <HASH>, <STRING>, ")
", <URI>, "inherit", <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGT
H_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_M
S>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <DIMENSION>, <PERCENTAGE>, <NUMBER>, <FUNCT
ION>, <IDENT>.
13:17:52.390 WARN - CSS error: null [4813:26] Error in style rule. Invalid token
 "\r\n". Was expecting one of: "}", ";".
13:17:52.390 WARN - CSS warning: null [4813:26] Ignoring the following declarati
ons in this rule.
13:17:52.390 WARN - CSS error: null [4825:21] Error in expression. Invalid token
 "=". Was expecting one of: <S>, <COMMA>, "/", <PLUS>, "-", <HASH>, <STRING>, ")
", <URI>, "inherit", <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGT
H_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_M
S>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <DIMENSION>, <PERCENTAGE>, <NUMBER>, <FUNCT
ION>, <IDENT>.
13:17:52.390 WARN - CSS error: null [4825:26] Error in style rule. Invalid token
 "\r\n". Was expecting one of: "}", ";".
13:17:52.390 WARN - CSS warning: null [4825:26] Ignoring the following declarati
ons in this rule.
13:17:52.406 WARN - CSS error: null [4883:15] Error in style rule. Invalid token
 ":". Was expecting one of: <S>, "}", <COMMA>, ";", "/", <PLUS>, "-", <HASH>, <S
TRING>, <URI>, "!", "inherit", <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_M
M>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD
>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <DIMENSION>, <PERCENTAGE>, <NUMBE
R>, <FUNCTION>, <IDENT>.
13:17:52.406 WARN - CSS warning: null [4883:15] Ignoring the following declarati
ons in this rule.
13:17:52.422 WARN - CSS error: null [6122:29] Error in expression. Invalid token
 "=". Was expecting one of: <S>, <COMMA>, "/", <PLUS>, "-", <HASH>, <STRING>, ")
", <URI>, "inherit", <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGT
H_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_M
S>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <DIMENSION>, <PERCENTAGE>, <NUMBER>, <FUNCT
ION>, <IDENT>.
13:17:52.422 WARN - CSS error: null [6122:34] Error in style rule. Invalid token
 "\r\n\t". Was expecting one of: "}", ";".
13:17:52.422 WARN - CSS warning: null [6122:34] Ignoring the following declarati
ons in this rule.
13:17:52.781 WARN - CSS error: null [15:26] Error in expression. Invalid token "
=". Was expecting one of: <S>, <COMMA>, "/", <PLUS>, "-", <HASH>, <STRING>, ")",
 <URI>, "inherit", <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGTH_
IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_MS>
, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <DIMENSION>, <PERCENTAGE>, <NUMBER>, <FUNCTIO
N>, <IDENT>.
13:17:52.781 WARN - CSS error: null [15:31] Error in style rule. Invalid token "
\n". Was expecting one of: "}", ";".
13:17:52.781 WARN - CSS warning: null [15:31] Ignoring the following declaration
s in this rule.
13:17:52.781 INFO - Done: /session/1301505458797/title
13:17:52.781 INFO - Executing: [find element: By.xpath: //*[@id='divHeader']/div
[1]/a[5] at URL: /session/1301505458797/element)
13:17:52.797 INFO - Done: /session/1301505458797/element
13:17:52.797 INFO - Executing: [click: 1 org.openqa.selenium.support.events.Even
tFiringWebDriver$EventFiringRenderedWebElement@18b1f8f] at URL: /session/1301505
458797/element/1/click)
13:17:52.797 INFO - Done: /session/1301505458797/element/1/click
13:17:52.797 INFO - Executing: [implicitly wait: 10000] at URL: /session/1301505
458797/timeouts/implicit_wait)
13:17:52.797 INFO - Done: /session/1301505458797/timeouts/implicit_wait
13:17:52.797 INFO - Executing: [find element: By.id: tab_Home at URL: /session/1
301505458797/element)
13:18:03.359 WARN - Exception thrown
org.openqa.selenium.NoSuchElementException: Unable to locate element with ID: ta
b_Home
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.vers
ion: '1.6.0_22'
Driver info: driver.version: EventFiringWebDriver
        at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElementById(HtmlUnitD
river.java:662)
        at org.openqa.selenium.By$1.findElement(By.java:66)
        at org.openqa.selenium.htmlunit.HtmlUnitDriver$5.call(HtmlUnitDriver.jav
a:1185)
        at org.openqa.selenium.htmlunit.HtmlUnitDriver$5.call(HtmlUnitDriver.jav
a:1)
        at org.openqa.selenium.htmlunit.HtmlUnitDriver.implicitlyWaitFor(HtmlUni
tDriver.java:932)
        at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDrive
r.java:1182)
        at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDrive
r.java:368)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.openqa.selenium.support.events.EventFiringWebDriver$2.invoke(Even
tFiringWebDriver.java:95)
        at $Proxy1.findElement(Unknown Source)
        at org.openqa.selenium.support.events.EventFiringWebDriver.findElement(E
ventFiringWebDriver.java:171)
        at org.openqa.selenium.remote.server.handler.FindElement.call(FindElemen
t.java:49)
        at org.openqa.selenium.remote.server.handler.FindElement.call(FindElemen
t.java:1)
        at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
        at java.util.concurrent.FutureTask.run(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source
)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
13:18:03.359 WARN - Exception: Unable to locate element with ID: tab_Home
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.vers
ion: '1.6.0_22'
Driver info: driver.version: EventFiringWebDriver

Ivo Grootjes

unread,
Mar 30, 2011, 6:58:53 PM3/30/11
to webdriver
Did you try this code using the firefoxdriver? It doesn''t seem to
work for me in firefox either... neither can't find an element with
tab_home as id myself
> 13:17:52.390 WARN - CSS warning: null [4778:15] Ignoring the following ...
>
> meer lezen »

lior grinfeld

unread,
Apr 11, 2011, 10:01:40 AM4/11/11
to webdriver
was this issue resolved ?

i am facing issues trying to migrate my test from selenium 1 =>
selenium 2.
i do not get the confidence that i can use it just yet.
specially using HtmlUnit in C#. selenium htmlunit driver does not find
element that firefox driver find.
using selenium sever 2.0b3

trace:

*** Failures ***
Execute
OpenQA.Selenium.WebDriverException: Cannot locate element used to
submit form
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version:
'6.1', java.version: '1.6.0_20'
Driver info: driver.version: unknown
at
OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response
errorResponse) in e:\Projects\WebDriver\trunk\dotnet\src
\WebDriver.Remote\RemoteWebDriver.cs:line 955
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(DriverCommand
driverCommandToExecute, Dictionary`2 parameters) in e:\Projects
\WebDriver\trunk\dotnet\src\WebDriver.Remote\RemoteWebDriver.cs:line
779
at OpenQA.Selenium.Remote.RemoteWebElement.SendKeys(String text) in
e:\Projects\WebDriver\trunk\dotnet\src\WebDriver.Remote
\RemoteWebElement.cs:line 182
at Selenium2.DelverTests.Search() in C:\work\TestProjects
\TestProjects\Selenium2\DelverTests.cs:line 61

where the code is very simple
IWebElement searchbox = _driver.FindElement(By.Id("searchText"));
searchbox.SendKeys("white");
searchbox.SendKeys(Keys.Enter); => same with the line
searchbox.Submit();

any ideas why?

10X,
Lior


Kathleen Jacobs

unread,
Apr 11, 2011, 11:11:23 AM4/11/11
to webd...@googlegroups.com
I was never able to fix the problem.  It never seemed to log in for me or actually do anything.
It would say it posted a comment, but if i went to check the comment or verify it was posted, it wasn't there (as an example)
Or Logging in


lior grinfeld

unread,
Apr 12, 2011, 2:39:09 AM4/12/11
to webdriver

is there a bug on this issue ?


On Apr 11, 6:11 pm, Kathleen Jacobs <katidjac...@gmail.com> wrote:
> I was never able to fix the problem.  It never seemed to log in for me or
> actually do anything.
> It would say it posted a comment, but if i went to check the comment or
> verify it was posted, it wasn't there (as an example)
> Or Logging in
>

Kathleen Jacobs

unread,
Apr 12, 2011, 9:35:29 AM4/12/11
to webd...@googlegroups.com, lior grinfeld
Don't think so.  It does not seem like everyone is having the problem.

Ivo Grootjes

unread,
Apr 13, 2011, 7:09:19 AM4/13/11
to webdriver
Kathleen, does your test work in firefox? because it didn't work in
firefox for me when i tried it.

On 12 apr, 15:35, Kathleen Jacobs <katidjac...@gmail.com> wrote:
> Don't think so.  It does not seem like everyone is having the problem.
>

Ivo Grootjes

unread,
Apr 13, 2011, 7:11:12 AM4/13/11
to webdriver
lior, how do you create the htmlunit driver? what is the value of
pagesource before you try to locate the element? Does the pagesource
contain the element? Are you using https / proxy?

lior grinfeld

unread,
Apr 13, 2011, 10:44:21 AM4/13/11
to webdriver

I create the driver like in the example

var remoteServer = new Uri("http://localhost:4444/wd/hub/");
ICapabilities desiredCapabilities = DesiredCapabilities.HtmlUnit();
driver = new RemoteWebDriver(remoteServer, desiredCapabilities);
driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 30));
//go to url
driver.Navigate().GoToUrl("http://mypage");
//do something
IWebElement searchbox = _driver.FindElement(By.Id("searchText"));
searchbox.SendKeys("white");
searchbox.SendKeys(Keys.Enter); //send [enter] key to the control.

i do not use https nor do i use proxy.
i do not understand the question about the page source.

Ivo Grootjes

unread,
Apr 13, 2011, 11:24:18 AM4/13/11
to webdriver
Does your page use javascript? you might try to set
IsJavaScriptEnabled = true on the capabilities object.

What i mean with the pagesource is, for debugging purposes u could
check the value of _driver.PageSource to check if the html contains
the element you are trying to find.

Your test fails on the searchbox.Submit(); line?

Kathleen Jacobs

unread,
Apr 13, 2011, 12:20:14 PM4/13/11
to webd...@googlegroups.com
Mine never worked in Firefox. 
It acted like it did but clicking submit or logging into something never actually worked.

If i typed a comment in and hit submit, the test would come back as pass. if i went to the site to check the comment i posted, no comment was ever posted.

Ivo Grootjes

unread,
Apr 13, 2011, 8:07:55 PM4/13/11
to webdriver
I think it's best to first try getting tests to work in firefox before
trying to run them using htmlunitdriver. The firefoxdriver is stable,
you don't have to go through remotewebdriver and you can actually see
what's going on. So i suggest you first try to get it to work using
the firefoxdriver. If it's still not working in firefox please start a
new thread which outlines what you do because this thread is becoming
a mess.

lior grinfeld

unread,
Apr 14, 2011, 4:40:32 AM4/14/11
to webdriver

lets do it line by line:
//this line work fine - it find the element
IWebElement searchbox = _driver.FindElement(By.Id("searchText"));
//this line works - i can see in the page source that the "white" is
in the text box
searchbox.SendKeys("white");
//this line does not work - element was not found by html driver
searchbox.SendKeys(Keys.Enter); //send [enter] key to the control.
//tried to replace it with this one - drive find the element but the
action was not performed
driver.FindElement(By.Id("searchBtn")).Click();

i did try to set desiredCapabilities.IsJavaScriptEnabled = true; but
i get error that the property IsJavaScriptEnabled has no setter . any
ideas about this one?

lior grinfeld

unread,
Apr 14, 2011, 5:03:06 AM4/14/11
to webdriver


i did set this one
ICapabilities desiredCapabilities =
DesiredCapabilities.HtmlUnitWithJavaScript();

still the same

Ivo Grootjes

unread,
Apr 14, 2011, 6:45:07 AM4/14/11
to webdriver
So the searchbox element can be found the first time but the second
time it cannot be found?

string htmlBeforeEnter = _driver.PageSource;
searchbox.SendKeys(Keys.Enter); //send [enter] key to the control.

Whats the value of htmlBeforeEnter? I assume it just contains the
searchText element? You still receive a NoSuchElementException? Or do
you receive the OpenQA.Selenium.WebDriverException: Cannot locate
element used to
submit form here?

I can image there's a problem with submit but I think clicking a
submit button should at lease work.

string htmlBeforeSearchButtonClick = _driver.PageSource;
driver.FindElement(By.Id("searchBtn")).Click();

Does htmlBeforeSearchButtonClick contain the searchBtn element? what
exception are you getting here?

I've also got problems using htmlunit but it has something to do with
a proxy, without a proxy im able to fill out forms, click buttons etc.
just fine.

If we can't get this to work maybe you can try to minimalize the
testhtml and submit an Issue?

Kathleen Jacobs

unread,
Apr 14, 2011, 10:16:43 AM4/14/11
to webd...@googlegroups.com, Ivo Grootjes
I'm sorry. Answered that wrong. I run tests in Webdriver fine using firefoxdriver. 
My only problem goes from when i switch to htmlunit.

lior grinfeld

unread,
Apr 14, 2011, 11:00:29 AM4/14/11
to webdriver

searchBox - find element works

searchbox.SendKeys(Keys.Enter); - works

searchbox.Submit() - NoSuchElementException

in page source the element exists

driver.FindElement(By.Id("searchBtn")).Click(); - find element but
looks like nothing happens on my page

in page source instead of getting search result page - new page should
be loaded - i am still in the same page.

strangely - i run the same test against google search and it worked.

seselnium 1 - works on my page
firefox driver - works on my page
html driver - does not work on my page - same logic works on google.

so , proxy issues are out , page is fully loaded with all elements
but....
i will try to investigate this some more...i will let you know my
results





lior grinfeld

unread,
Apr 17, 2011, 4:32:27 AM4/17/11
to webdriver

did some more digging into it.

since the same test pass on google and failed on my site - i tried to
find the difference between google search box and my site search box.

i found out that google had input for the textBox and for the search
btn - and the search btn had type submit.
In My site the textBox is of type input but the search btn is div.
changing the btn from div to input and adding type submit made the
test pass.

the thing that i do not understand are:
why firefox driver and html driver act differently?
why click on the search btn when it was div and html driver ended with
no action with html driver?
will selenium 2 force me to have all btn to have type submit to make
the tests pass with html driver?




Ivo Grootjes

unread,
Apr 17, 2011, 8:11:04 PM4/17/11
to webdriver
can you post the relevant html? what does a click on the div do
exactly? i mean how does it submit?

lior grinfeld

unread,
Apr 20, 2011, 7:43:17 AM4/20/11
to webdriver

the HTML source is:
<div id="searchContainer" class='Float'>
<form method="get" id='search' class="SearchForm" action="/search/
Products">
<div class="Button High Large SearchIn Float HasIcon">
<span class="DropDownIcon"></span>
<span class="DropDownValue">Products</span>
</div>
<input id='searchText' class="SearchText Float" type="text"
name="q" title="Search terms" value="" />
<div class="Float SearchBtnContainer">
<div id='searchBtn' class="Button High Large Float HasIcon">
<span class="SearchIcon"></span>
Search
</div>
</div>
<div class="Breaker"></div>
</form>
</div>

when you press the button in the div it activate javascript that do
the search.
//searchContainer.find('#searchBtn').live('click', function() {
//form.submit();
//});

lior grinfeld

unread,
Apr 20, 2011, 7:41:34 AM4/20/11
to webdriver

the HTML source is:
<div id="searchContainer" class='Float'>
<form method="get" id='search' class="SearchForm" action="/search/
Products">
<div class="Button High Large SearchIn Float HasIcon">
<span class="DropDownIcon"></span>
<span class="DropDownValue">Products</span>
</div>
<input id='searchText' class="SearchText Float" type="text"
name="q" title="Search terms" value="" />
<div class="Float SearchBtnContainer">
<div id='searchBtn' class="Button High Large Float HasIcon">
<span class="SearchIcon"></span>
Search
</div>
</div>
<div class="Breaker"></div>
</form>
</div>

when you press the button in the div it activate javascript that do
the search.
searchContainer.find('#searchBtn').live('click', function() {
form.submit();
});
Reply all
Reply to author
Forward
0 new messages