Relative Locators- LeftOf, RightOf,Above, Below

 



WebDriver driver = new ChromeDriver();
driver.get("https://www.aqi.in/dashboard/canada");
Thread.sleep(4000);
WebElement city = driver.findElement(By.linkText("Creston, Canada"));

String rightAQIUS = driver.findElement(RelativeLocator.with(By.tagName("p")).toRightOf(city)).getText();
System.out.println(rightAQIUS);

String leftOf = driver.findElement(RelativeLocator.with(By.tagName("p")).toLeftOf(city)).getText();
System.out.println(leftOf);

String aboveText = driver.findElement(RelativeLocator.with(By.tagName("p")).above(city)).getText();

System.out.println(aboveText);

String belowText = driver.findElement(RelativeLocator.with(By.tagName("p")).below(city)).getText();

System.out.println(belowText);



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


WebElement lastName = driver.findElement(By.cssSelector("label[for='input-lastname']"));

String aa = driver.findElement(RelativeLocator.with(By.tagName("label")).below(lastName)).getText();

System.out.println(aa + "below");

String bb = driver.findElement(RelativeLocator.with(By.tagName("label")).above(lastName)).getText();

System.out.println(bb + "above");



Comments

Popular posts from this blog

Implicit and Explicit Waits,FluentWait,PageLoadTimeOut

A Interview Questions- selenium