Locating a text box and enter a value in it

In this section we will see how to locate a textbox element and entering a value in it. Lets take an example of Facebook page where we will enter an email id for login.


Locating a textbox and enter a value in it

Inspecting the text box element:

Locating a textbox and enter a value in it

Example code:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class TestClass {
 public static void main(String[] args) {
  // TODO Auto-generated method stub

  System.setProperty("webdriver.gecko.driver", "./MyProject/driver/geckodriver.exe");
  WebDriver driver = new FirefoxDriver();
  driver.get("https://www.facebook.com/");

  // Locating and entering value in the text box
  WebElement email = driver.findElement(By.id("email"));
  email.sendKeys("helpmevinod@gmail.com");
 }
}


<-- Previous || Next -->

No comments:

Post a Comment