Pressing Ctrl + A in Selenium WebDriver
One more solution (in Java, because you didn't tell us your language - but it works the same way in all languages with Keys
class):
String selectAll = Keys.chord(Keys.CONTROL, "a");
driver.findElement(By.whatever("anything")).sendKeys(selectAll);
You can use this to select the whole text in an <input>
, or on the whole page (just find the html
element and send this to it).
For using Selenium Ruby bindings:
There's no chord()
method in the Keys
class in Ruby bindings. Therefore, as suggested by Hari Reddy, you'll have to use Selenium Advanced user interactions API, see ActionBuilder
:
driver.action.key_down(:control)
.send_keys("a")
.key_up(:control)
.perform
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"));
how to press Ctrl + ] in Selenium web driver
Use either
Actions action=new Actions(driver);
action.SendKeys(OpenQA.Selenium.Keys.Control + "]").Build().Perform();
or
yourWebElement.SendKeys(Keys.Control + "]");
Related Topics
Error: While Executing Gem ... (Gem::Filepermissionerror)
Trying to Learn/Understand Ruby Setter and Getter Methods
Oo Design in Rails: Where to Put Stuff
Ruby: What Does 'Require: False' in Gemfile Mean
Why Doesn't Ruby Support Method Overloading
How to Track System-Specific Config Files in a Repo/Project
What's the Difference Between Ruby'S Dup and Clone Methods
Look Up All Descendants of a Class in Ruby
Connecting Rails 3.1 With Multiple Databases
How to "Pretty" Format Json Output in Ruby on Rails
How to Match All Occurrences of a Regex