How to Press Shift+Tab Key Using Selenium Java

Profile picture for user arilio666

Shift+Tab key generally goes to the end of the selection area within the webpage, and this is what we will be discussing in this article on how we can perform this key press in selenium using java.

We can do this by using the actions class.

  • Consider this Facebook signup page where when we press the shift and tab keys together, it goes to the signup button, which is at the end and highlights it.
  • Let us check this out with our code.
        ChromeDriver driver = new ChromeDriver();
        driver.findElement(By.xpath("//a[@class='_42ft _4jy0 _6lti _4jy6 _4jy2 selected _51sy']")).click();
        Actions actions = new Actions(driver);
  • Using the actions class, we are invoking the key down and up event and using send keys to mimic the tab key as a combination.
  • This will make the web driver press the shift+tab keys together, highlighting the signup button.