I want to select all content by pressing Ctrl+a from keyboard by using WebDriver with Java. I wrote the following code:
Actions actionObj = new Actions(driver); actionObj.keyDown(Keys.CONTROL) .sendKeys(Keys.chord("A")) .keyUp(Keys.CONTROL) .perform();
Unfortunately, it did not work. What's the wrong in my WebDriver Java code?
We can also perform a CTRL+A press by simply using the sendKeys() method. We have to pass Keys. CONTROL along with the string A by concatenating with +, as an argument to the method.
How to press Ctrl+A to select all content in a page by Selenium WebDriver using Java.
Select all text in a textbox Selenium RC using Ctrl + A.
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"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With