我想双击谷歌页面的搜索输入框,它应该被选中
这是我的代码:
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();
}
但文本未被选中。
1.为什么不工作?
2.我们总是使用 By.ID,By.name 等为什么我们不使用 ById.Id ByName.name 等 如果我们可以在应该使用它的地方使用它,如果不能,为什么我们没有使用它?
最佳答案
如果你想选择所有的文本你可以这样做...
driver.findElement(By.xpath("xpath")).sendKeys(Keys.chord(Keys.CONTROL, "a"));
关于java - 使用 DoubleClick 从 WebDriver Java 选择文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20302382/