How can I make a selenium click() work the same as a manual mouse click?
I have recently upgraded GWT from 1.7.1 to 2.0. Some selenium tests (SeleniumRC v1.0.1, IE7)
I wanted to post the code that finally worked for me following useful comments from AutomatedTester.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverBackedSelenium;
import org.openqa.selenium.ie.InternetExplorerDriver;
import com.thoughtworks.selenium.Selenium;
public class TestTreeClick {
public static void main(String[] args) {
WebDriver driver = new InternetExplorerDriver();
Selenium selenium = new WebDriverBackedSelenium(driver, "http://gwt.google.com/samples/Showcase/Showcase.html#CwTree");
selenium.open("http://gwt.google.com/samples/Showcase/Showcase.html#CwTree");
selenium.click("gwt-debug-cwTree-staticTree-root-child0-content");
}
}
You don't actually need to "click" on that button, but press "Enter" on it instead.
See http://dingyichen.livejournal.com/23628.html
It seems that WebDriver can do it like this.
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class Example {
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new InternetExplorerDriver();
driver.get("http://gwt.google.com/samples/Showcase/Showcase.html#CwTree");
WebElement element = driver.findElement(By.id("gwt-debug-cwTree-staticTree-root-child0-content"));
element.click();
}
}
I'd still like to be able to do it with Selenium. It may be that a future Selenium release will more fully incorporate WebDriver, and everything will be wonderful again. But I guess this works for now.
Unfortunately having a look at this case I have not been able to replicate clicking with Selenium. I have seen a number of people complaining that they can't use Selenium with GWT and one of the more famous teams have that issue. The Google Wave development team have started using WebDriver to test their code.
Now the good thing is that there currently a project to merge Selenium and WebDriver as they have their strengths and weaknesses and a number of them are in different areas so the final product will be amazing.
I believe that they may have a working version of the WebDriverBackedSelenium at Google Code so all you would need to do is update the instantiation of Selenium and it should start using the WebDriver code to run your test.