Hello,
I am in the midst of tracing an issue discovered using watir-
webdriver, but have been able to reproduce the same issue with
selenium-webdriver. Here's a quick summary. I'm looking for insight
into how all these components communicate and link together -
specifically how selenium-webdriver communicates with the headless
HTMLunit browser via selenium-server-standalone.jar.
Repro:
- I have a simple HTML page with one form and a single image input
element. The form method is get and loads another static HTML page.
This is sufficient to see the issue. Included at bottom of this
messgae.
- The test code is at the bottom of this message.
Results are as follows:
htmlunit:
http://path.to.server/htmlUnitTestPost.html?input-image-test=
firefox:
http://path.to.server/htmlUnitTestPost.html?input-image-test.x=0&input-image-test.y=0
ie:
http://path.to.server/htmlUnitTestPost.html?input-image-test.x=13&input-image-test.y=14
Analysis:
When selenium-webdriver (via remote htmlunit) clicks on a input image
it does not provide a default x/y coordinate, and as a result the page
is submitted as if a submit button was clicked not an input button. In
addition to not providing a default x/y, webdriver itself does not
provide a clickAt equivalent.
Discussion:
I initially assumed it was HTMLunit that was the cause and that it
didn't behave like other browsers. So I then tried to directly control
HTMLunit with Java - it behaves correctly returning:
http://path.to.server/htmlUnitTestPost.html?input-image-test.x=0&input-image-test.y=0
Which confused me: I checked out the read-only selenium source code,
and looked through HTMLunit, it does correctly implement the click
method providing a position and yielding the correct result (as
demonstrated above). Why doesn't selenium webdriver correctly wrap the
HTMLunit click method to make it behave in the expected way for input
images? How does webdriver interact with elements in the headless
HTMLunit browser since it doesn't seem to call the native element
methods?
I'm happy to submit the code patch once I figure out exactly where the
disconnect is occurring. Any thoughts or suggestions?
Thanks,
Michael
Ruby test:
require "test/unit"
require "rubygems"
require "selenium-webdriver"
class HtmlUnitTest < Test::Unit::TestCase
def test_html_unit
caps =
Selenium::WebDriver::Remote::Capabilities.htmlunit(:javascript_enabled
=> true)
preform_test(caps)
end
def test_firefox
caps =
Selenium::WebDriver::Remote::Capabilities.firefox(:javascript_enabled
=> true)
preform_test(caps)
end
def test_internet_explorer
caps =
Selenium::WebDriver::Remote::Capabilities.ie(:javascript_enabled =>
true)
preform_test(caps)
end
def preform_test(caps)
driver = Selenium::WebDriver.for(
:remote,
:url => "
http://127.0.0.1:4444/wd/hub",
:desired_capabilities => caps
)
driver.navigate.to "
http://path.to.server/htmlUnitTest.html"
driver.find_element(:name, 'input-image-test').click
puts driver.current_url
end
end # end HtmlUnitTest class
Java to directly control HTMLunit (snippet):
final WebClient webClient = new WebClient();
final HtmlPage page = webClient.getPage("
http://path.to.server/
htmlUnitTest.html");
HtmlForm form = page.getFormByName("theform");
final HtmlImageInput button = form.getInputByName("input-image-
test");
button.click();
System.out.println(page.getUrl());
HTML Code (snippet):
<form name="theform" action="htmlUnitTestPost.html" method="get">
<input type="image" name="input-image-test" />
</form>