J'essaie d'exécuter un petit exemple d'application en utilisant HtmlUnitDriver
dans Eclipse. Mon code est le suivant:Sélection d'éléments DOM dans WebDriver
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
public class TestHtmlUnitDriver {
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());
}
}
Mais il donne l'erreur suivante (comme indiqué dans la console d'Eclipse):
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element with name: q
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0_23'
Driver info: driver.version: TestHtmlUnitDriver
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElementByName(HtmlUnitDriver.java:714)
at org.openqa.selenium.By$4.findElement(By.java:148)
at org.openqa.selenium.htmlunit.HtmlUnitDriver$5.call(HtmlUnitDriver.java:1185)
at org.openqa.selenium.htmlunit.HtmlUnitDriver$5.call(HtmlUnitDriver.java:1)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.implicitlyWaitFor(HtmlUnitDriver.java:932)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:1182)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:368)
at com.comverse.plus.selenium.TestHtmlUnitDriver.main(TestHtmlUnitDriver.java:19)
que quelqu'un peut me aider à résoudre mon problème?
Il a dit " Impossible de localiser l'élément avec le nom: q ". Y a-t-il un élément nommé 'q'? – nitind