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

Note 3 - Sibling - Child To Parent Traverse

The document contains code examples using Selenium locators and window handling methods. It imports Selenium packages and defines classes with main methods that set the ChromeDriver property, create ChromeDriver instances, navigate to URLs, and use XPath locators to find and output elements.

Uploaded by

dwivedia670
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)
47 views2 pages

Note 3 - Sibling - Child To Parent Traverse

The document contains code examples using Selenium locators and window handling methods. It imports Selenium packages and defines classes with main methods that set the ChromeDriver property, create ChromeDriver instances, navigate to URLs, and use XPath locators to find and output elements.

Uploaded by

dwivedia670
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 org.openqa.selenium.

By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

public class Locators3 {

public static void main(String[] args) {

// TODO Auto-generated method stub

System.setProperty("webdriver.chrome.driver",
"/Users/rahulshetty/Documents/chromedriver");

WebDriver driver = new ChromeDriver();

// Sibling - Child to parent traverse

//header/div/button[1]/following-sibling::button[1]

driver.get("https://rahulshettyacademy.com/AutomationPractice/");

System.out.println(driver.findElement(By.xpath("//header/div/button[1]/following-
sibling::button[1]")).getText());

System.out.println(driver.findElement(By.xpath("//header/div/button[1]/
parent::div/button[2]")).getText());

*****************************************************************

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

public class WindowActivities {

public static void main(String[] args) {

// TODO Auto-generated method stub

System.setProperty("webdriver.chrome.driver",
"/Users/rahulshetty/Documents/chromedriver");

WebDriver driver = new ChromeDriver();

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

driver.get("http://google.com");

driver.navigate().to("https://rahulshettyacademy.com");

driver.navigate().back();

driver.navigate().forward();

You might also like