You are on page 1of 1

-> selenium relative locators introduced in 4.

0 :

import static org.openqa.selenium.support.locators.RelativeLocator.withTagName;


this line needs to be added manually as the package is static and hence, the IDE
will not suggest the package automatically.

above() : to locate element which is above a particular


supports only tagname -> example :
driver.findElement(withTagName("label").above(driver.findElement(By.xpath("//
div[@id='uniqueid']"))))
in other words : this element is located above(this element)

below() : ,toLeftOf(),toRightOf()
in other words : this element is located below(this element)
in other words : this element is located toLeftOf(this element) (in the html view
element needed is located to the left of a chosen element)
in other words : this element is located toRightOf(this element) (in the html view
element needed is located to the right of a chosen element)

-> taking weblement screenshot (partial screenshot)


WebElement element =
driver.findElement(By.name("name")).sendKeys(nameofFirstCourse);
File file = driver.findElement(By.name("name")).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(file, new File("C:\\Users\\agarw\\Desktop\\logo.png"));

-> capturing height and width of a webelement for UX validation :

You might also like