我创建了一个示例应用程序,其中我已经打开了google.com并在文本框中输入了一些文本。
应用程序可以打开google.com但无法识别元素。
示例应用程序:
public void testGoogle()抛出异常{
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities = DesiredCapabilities.android();
WebDriver driver = new AndroidDriver(capabilities);
// And now use this to visit Google
driver.get("http://www.google.co.in");
Thread.sleep(4000);
// Find the text input element by its name
WebElement element = driver.findElement(By.id("gs_htif0"));
// Enter something to search for
element.sendKeys("Welcome");
// 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());
driver.quit();
}
你能帮忙吗?
我正在使用android模拟器和selenium webdriver。
谢谢, 苛刻
答案 0 :(得分:2)
public void testGoogle() throws Exception {
WebDriver driver = new AndroidDriver();
driver.get("http://www.google.co.in");
Thread.sleep(4000);
WebElement element = driver.findElement(By.name("q"));
element.sendKeys("Welcome");
element.submit();
System.out.println("Page title is: " + driver.getTitle());
driver.quit();
}
我只更改了find.element部分并删除了所需的功能,现在它正常工作