import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.Point; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; public class GetcoordinatesOfelement { public static void main(String args[]) { // Initialize driver WebDriver dr = new FirefoxDriver(); //Maximize browser window dr.manage().window().maximize(); //Go to URL dr.get("http://www.google.com"); //Set timeout dr.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); //Locate element for which you wants to retrieve x y coordinates. WebElement element = dr.findElement(By.partialLinkText("Gmail")); //Used points class to get x and y coordinates of element. Point point = element.getLocation(); int xcord = point.getX(); int ycord = point.getY(); System.out.println(xcord + ", " + ycord); //close firefox browser dr.close(); } }
How to get X,Y Coordinates Of element in selenium webdriver using java.
Subscribe to:
Post Comments (Atom)
Can u add how to click the element by cords
ReplyDelete