Author - StudySection Post Views - 35 views

Locating elements(visible/editable) with Selenium


Selenium Webdriver is used to automate the testing. There are some visible and invisible, editable and non-editable elements on the webpage. We can access those elements using Selenium and check whether the element is accessible or not.

Locating an element:

An element can be located by ID, name, XPath, etc.

  1. By ID:
    To locate an element on a webpage using ID, we need to have a basic understanding of HTML.

    Steps to follow:

    1. driver.findElement(“id”));
    2. WebElement loginById = driver.findElement(“id”));

  2. By name:

    From the above image, we can see that the name for the login field is; ”data[User][email]”.
    1. driver.findElement(“name”));
    2. WebElement loginByName = driver.findElement(“name”));

  3. By XPath:

    • Right-click on the tag line for the login field from inspect elements.
    • Hover mouse over the “copy”, it’ll expand other options and then click on “Copy XPath”.


    1. driver.findElement(By.xpath(“xpath”));
    2. WebElement loginByxpath = driver.findElement(By.xpath(“xpath”));

Finding out the visible and editable fields using a program and implementing these locators

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
public class Test1 {
public static void main(String[] args) {
//setting up Chrome

//open chrome
ChromeDriver driver = new ChromeDriver();

//open URL

//locate element using name and enter value

//clear the value from textbox

//locate element with WebElment and enter value
WebElement eid = driver.findElement("UserEmail"));

//locate element using xpath and enter value
WebElement pass = driver.findElement(By.xpath("//*[@id=\"UserPassword\"]"));

//check if the textbox is visible and editable
boolean visible = eid.isDisplayed();
boolean enabled = eid.isEnabled();

if(visible==true && enabled==true) {
System.out.println("Email field is visible and editable");
System.out.println("Email field not visible and editable");

//confirm the value in the field
String fvalue = eid.getAttribute("value");
System.out.println("Email is correct");
System.out.println("Email not matching, entered email is "+fvalue);


Email field is visible and editable
Email not matching, entered email is

If you have skills in PHP programming and you want to enhance your carrier in this field, a PHP certification from StudySection can help you reach your desired goals. Both beginner level and expert level PHP Certification Exams are offered by StudySection along with other programming certification exams.

Leave a Reply

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