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

Selenium CSS Locator Example Code

The document is a Java class named CSSLocator that utilizes Selenium for web automation. It includes methods to create a WebDriver instance, locate a web element using a CSS selector, and retrieve an attribute from that element. The main method demonstrates the usage of these methods to interact with a web page element identified by the username CSS selector.

Uploaded by

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

Selenium CSS Locator Example Code

The document is a Java class named CSSLocator that utilizes Selenium for web automation. It includes methods to create a WebDriver instance, locate a web element using a CSS selector, and retrieve an attribute from that element. The main method demonstrates the usage of these methods to interact with a web page element identified by the username CSS selector.

Uploaded by

Vinith Reddy
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

import [Link].

*;
import [Link];
import [Link];
import [Link];//Add required imports

public class CSSLocator//DO NOT change the class name


{
String fname;
static WebDriver driver;
public WebDriver createDriver() //DO NOT change the method signature
{
driver=[Link]();
return driver;
//Implement code to create Driver from DriverSetup and return it
}

public WebElement getCSSLocator(WebDriver driver) //DO NOT change the method


signature
{
WebElement element=[Link]([Link]("#username"));
return element;
/*Replace this comment by the code statement to get the Web element of username*/
/*Find and return the element */

public String getName(WebElement element) //DO NOT change the method signature
{
String fname=[Link]("placeholder");
return fname;

//Get the attribute value from the element and return it


}

public static void main(String[] args){


CSSLocator pl=new CSSLocator();
driver=[Link]();
WebElement element=[Link](driver);
String hi=[Link](element);
//Add required code

}
}

You might also like