使用下面的简单测试代码,但 selenium 总是喜欢选择第二个谷歌建议结果作为搜索文本:
例如:
我输入“Selenium”,谷歌会给出如下建议列表:
Selenium
Selenium WebDriver
然后 webdriver 将始终选择“Selenium WebDriver”。但我使用 webdriver 将密钥作为“Selenium”发送。
是webdriver的错误吗?
public class HelloWorld {
private WebDriver driver;
@Before
public void setUp() {
System.setProperty("webdriver.ie.driver", "D:\\IEDriverServer.exe");
DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
caps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
driver = new InternetExplorerDriver(caps);
driver.get("http://www.google.com");
}
@After
public void tearDown() {
driver.quit();
}
@Test
public void testLitianyiNewsIsExisting() throws InterruptedException {
WebElement inputField = driver.findElement(By.name("q"));
inputField.sendKeys("selenium");
//Thread.sleep(5000);
driver.findElement(By.name("btnK")).submit();
}
}