【发布时间】:2016-09-01 07:55:45
【问题描述】:
我正在尝试在谷歌上搜索一些东西,让我们说“测试”。所以我想点击第一个搜索结果,但无法做到。请在下面找到我的代码。我尝试过使用 xpath、class 和 cssSelector。请帮忙。:
/**
* @param args
* @throws InterruptedException
*/
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("https://www.google.co.in/");
driver.findElement(By.id("lst-ib")).sendKeys("Testing" + Keys.ENTER);
Thread.sleep(5);
driver.findElement(
By.className("r"))
.click();
}
请同时查找 Inspect Element 结果:
软件测试 - 维基百科,免费的百科全书
【问题讨论】:
-
en.wikipedia.org/wiki/Software_testing">Software testing - 维基百科,免费的百科全书一个>
-
以上是我的 Inspect Element 结果
-
运行代码时发生了什么?它在我的机器上运行得很好。有什么错误吗?
标签: selenium-webdriver webdriver