How to use tab key (button) in selenium WebDriver?

There are multiple ways to perform Tab key functionality. Using Actions Class, Using SendKeys() method & few other. Let us talk about them one by one.

TAB Key using Actions Class in Selenium WebDriver

1. Using function sendKeys(Keys.Tab).

    WebElement inputField = driver.findElement(By.Locator("LocatorValue"));

2. If you are using Java then you can use Java ROBOT class to perform keyboard actions.

Robot robot = new Robot();
// Simulate key Events

3. You can use Ascii value in send key function like sendKeys(//0061); I am not sure the ASCII value of Tag it’s just an example.

4. Using Actions class. –

Basically, you need to have instance of Actions class and then call sendKeys with TAB as TAB key.
package learnAboutActionsClass;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;

public class TabKeyUsingActionsClass {

 public static void main(String[] args) {
  // TODO Auto-generated method stub
WebDriver driver = new FirefoxDriver();
  driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
  WebElement element = driver.findElement(By.xpath("//input[@class='search']"));
  element.sendKeys("text to be searched");
   Actions act = new Actions(driver);


Hope This Helps !!!!

Leave Comment

Your email address will not be published. Required fields are marked *

Looking for learning Framework Development from Scratch? Lookout for Detailed Framework Development videos on YouTube here -

Get the Framework code at Github Repo: