Q) Element Locators in Selenium
Q) Element Locators in Selenium
1) driver.get(“URL”);
Opens the specified URL in the Browser Window.
1) Note :-
For Handling Browser,Page Driver object (i.e driver) is enough.
For Remaining elements we have to use WebDriver methods
3) Some
Get Page Title ,
Get Page Source(i.e HTML source) , Get Page URL , etc…
In Selenium
Element locator value.
1) Locator :-
It is an address that identifies a web element uniquely within the web page
2) Selenium supports 8 Element Locators to recognize Elements in the WebPage :-
id,name
tagName,className
linkText,partialLinkText
cssSelector
xpath
Ex1) id
1) Syntax :- By.id(“id_value”);
1) driver.get(“URL”);
Opens a specified URL in the Browser’s window.
1) driver.navigate().to(“URL”);
To navigate to the page with the specified URL.
2) driver.close();
To close the focussed browser.
Q) Illustration
Launch a Browser Open www.learncpp.com
Wait for 10s ……Then close the browser
Thread.sleep(10000);
3) driver.quit();
3) driver.navigate().refresh()
To refresh the Current webpage in the Browser
Q) Illustration
Opens www.learncpp.com
Refreshes that page
Then Closes the browser
public static void main(String[] args)
{
// Starting the Google Chrome Browser
System.setProperty("webdriver.chrome.driver","G://Selenium Files/Selenium
Drivers/chromedriver.exe");
driver.navigate().refresh();
1) driver.findElement(By.ElementLocator(“value”)).sendKeys(“input_data“);
sendKeys() method enters the inpue_data into the Editbox/Textbox
input_data = String.
Find the Editbox/Textbox using Element locators.
Then the code becomes driver.element.sendKeys(“input_data”);
Where element = Textbox / Editbox.
2) driver.findElement(By.ElementLocator(“value”)).clear();
clear() method clears the data in the EditBox/Textbox
Find the Editbox/Textbox using Element locators.
Then the code becomes driver.element.sendKeys(“input_data”);
Where element = Textbox / Editbox.