5 java selenium selenium-webdriver
我想双击谷歌页面的搜索输入框,它应该被选中
这是我的代码:
WebDriver driver = new FirefoxDriver();
driver.navigate().to("http://www.google.com");
WebElement oWE = driver.findElement(By.name("q"));
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.presenceOfElementLocated(By.name("q")));
if (oWE.isDisplayed()) {
System.out.println("Displayed");
oWE.sendKeys("abcd");
driver.findElement(By.id("gbqfb")).click();
Actions oAction = new Actions(driver);
oAction.moveToElement(oWE);
oAction.doubleClick(oWE).build().perform();
}
Run Code Online (Sandbox Code Playgroud)
但未选择文本。
1.为什么它不工作?
2.我们总是使用 By.ID,By.name 等为什么我们不使用 ById.Id ByName.name 等如果我们可以在应该使用它的地方使用它 如果不能为什么我们不使用它?
如果你想选择所有文本,你可以这样做......
driver.findElement(By.xpath("xpath")).sendKeys(Keys.chord(Keys.CONTROL, "a"));
| 归档时间: |
|
| 查看次数: |
9504 次 |
| 最近记录: |