How to press Ctrl+A to select all content in a page by Selenium WebDriver using Java
To select the whole page:
driver.findElement(By.xpath("//body")).sendKeys(Keys.chord(Keys.CONTROL, "a"));
cssSelector is faster than xpath
. So it could be done by using CSSPath also. Below is the way:
driver.findElement(By.cssSelector("body")).sendKeys(Keys.chord(Keys.CONTROL, "a"));
Try to chord the Ctrl+A keys. The code below is working in my case:
element.sendKeys(Keys.chord(Keys.CONTROL, "a"));