How to get x and y coordinates of an element using Selenium Webdriver

package selenium_examples;


import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Sample {

public static void main(String[] args)
{

WebDriver driver = new FirefoxDriver();
driver.get("http://google.com");
System.out.println("X Position= "+ driver.findElement(By.name("btnK")).getLocation().getX());
System.out.println("Y Position= "+ driver.findElement(By.name("btnK")).getLocation().getY());

}
}


Output:-

X Position= 373
Y Position= 386


No comments:

Related Posts Plugin for WordPress, Blogger...