gpt4 book ai didi

java - 使用 DoubleClick 从 WebDriver Java 选择文本

转载 作者:搜寻专家 更新时间:2023-11-01 03:38:55 26 4
gpt4 key购买 nike

我想双击谷歌页面的搜索输入框,它应该被选中

这是我的代码:

    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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com