0% found this document useful (0 votes)
11 views2 pages

TC Locators

The document is a Java program that uses Selenium WebDriver to automate browser interactions on a demo website. It demonstrates various methods to locate web elements using different strategies such as ID, name, class, link text, partial link text, CSS selectors, and XPath. The program also checks the visibility and enabled status of a login button, retrieves text from a tab, and gets an attribute value from a logo element before closing the browser.

Uploaded by

sharmamonish1985
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

TC Locators

The document is a Java program that uses Selenium WebDriver to automate browser interactions on a demo website. It demonstrates various methods to locate web elements using different strategies such as ID, name, class, link text, partial link text, CSS selectors, and XPath. The program also checks the visibility and enabled status of a login button, retrieves text from a tab, and gets an attribute value from a logo element before closing the browser.

Uploaded by

sharmamonish1985
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import java.util.

List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class TCLocators {

public static void main(String[] args) {


// TODO Auto-generated method stub
String TagName;
System.setProperty("webdriver.chrome.driver", "D:\\JAVA Basic\\Software
Automation\\chromedriver_win32\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("http://demo.sentrifugo.com");

//Maximize the window

driver.manage().window().maximize();

//.....FindElement..........//

//Finding an Element Using ID

TagName=driver.findElement(By.id("username")).getTagName();
System.out.println("ID:" +TagName);

//Finding an Element using Name


TagName=driver.findElement(By.name("username")).getTagName();
System.out.println("Name:" +TagName);

//Finding an Element using class

TagName=driver.findElement(By.className("demo_div_block")).getTagName();
System.out.println("class:" +TagName);

//Finding an Element using linkText


TagName=driver.findElement(By.linkText("Home")).getTagName();
System.out.println("Home:" +TagName);

//Finding an Element using Partial linkText


TagName=driver.findElement(By.partialLinkText("Ho")).getTagName();
System.out.println("PartialLinkText:" +TagName);

//Finding an Element using CSS--Tag&Attribute


TagName=driver.findElement(By.cssSelector("input[value='Log
In']")).getTagName();
System.out.println("CSS:" +TagName);

//Finding an Element using Xpath

TagName=driver.findElement(By.xpath("//*[@id='loginsubmit']")).getTagName();
System.out.println("Xpath:" +TagName);

//webElement

WebElement TxtBoxPassword=driver.findElement(By.id("password"));
TagName=TxtBoxPassword.getTagName();
System.out.println("WebElement:" +TagName);

//.................FindElements............

List<WebElement>allControls=driver.findElements(By.xpath("//ul[@class='credentials_
list']/li"));
System.out.println(allControls.size());

//.......isDisplayed.............

if(driver.findElement(By.id("loginsubmit")).isDisplayed())
{
System.out.println("Login button is Visible");
}
else
{
System.out.println("Login button is not Visible");

//...........isEnabled......................

if(driver.findElement(By.id("loginsubmit")).isEnabled())
{
System.out.println("Login button is Enabled");
}
else
{
System.out.println("Login buttin is not Enabled");
}

//............GetText..................

if(driver.findElement(By.id("abouttab")).getText().equals("Help"))
{
System.out.println("Help Text is Written");
}
else
{
System.out.println("Help Text is Not Written");
}

//...................GetAtrribute...........................

String
AttrValue=driver.findElement(By.className("logo")).getAttribute("onclick");
System.out.println(AttrValue);

driver.close();

You might also like