Handling Edit Box

Manual description

  • Check for display status
  • Check for enabled status
  • Enter a value
  • Return the value
  • Clear the value
  • Return element value type

Now try to perform above scenarios with Selenium WebDriver Steps:

package HandlingElementsInSelenium;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class HandlingEditBox {
	public static void main(String[] args) throws InterruptedException {	
	System.setProperty("webdriver.chrome.driver", "F:\\chromedriver.exe");
	WebDriver driver = new ChromeDriver();
	driver.manage().window().maximize();
	driver.get("https://www.facebook.com/");	
		
	//Check for display status
	       WebElement userNameBox = driver.findElement(By.id("email"));
	       boolean displayUNBox = userNameBox.isDisplayed();
	       System.out.println("Username bos is displayed :- "+displayUNBox);
	       
	 //Check for enabled status
	       boolean checkEnabled = userNameBox.isEnabled();
	       System.out.println("Username box is enabled :- "+checkEnabled);
	       
	 //Enter a value
	       String userkeyValue = "SeleniumTest";
	       userNameBox.sendKeys(userkeyValue);
	       Thread.sleep(3000);
	       
	 //Get the attribute of an element /Return the value
	       String val = userNameBox.getAttribute("value");
	       System.out.println("Entered value in username box is :- "+val); 
	       
	//Return element value type
	       String elementValType = userNameBox.getAttribute("type");
	       System.out.println("Username box type is :- "+elementValType);
	       
	//Clear the entered value
	       userNameBox.clear();
	       
    driver.close();
	}
}

Next

Leave a comment

Design a site like this with WordPress.com
Get started