Reputation:
I want to do double click on search inputbox of google page and it should be selected
This is my code :
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();
}
but text is not selected.
1.Why it is not working?
2.We always use By.ID,By.name etc why we do not use ById.Id ByName.name etc if we can use this where it should be used if not why we did not use this?
Upvotes: 5
Views: 10593
Reputation: 395
Your code is perfect: instead of trying to "double click" the web element you've given, try some other element.
Try this:
WebDriver driver = new FirefoxDriver();
driver.navigate().to("http://jsbin.com/obeyu4/3");
WebDriverWait wait = new WebDriverWait(driver, 30);
Actions act = new Actions(driver);
act.doubleClick(driver.findElement(By.id("golink"))).perform();
Thread.sleep(3000);
System.out.println(driver.getTitle());
Upvotes: 0
Reputation: 626
if you want to select all the text you can do it like this...
driver.findElement(By.xpath("xpath")).sendKeys(Keys.chord(Keys.CONTROL, "a"));
Upvotes: 3