官术网_书友最值得收藏!

The getLocation() method

The getLocation method can be executed on all the WebElements. This is used to get the relative position of an element where it is rendered on the web page. This position is calculated relative to the top-left corner of the web page of which the (x, y) coordinates are assumed to be (0, 0). This method will be of use if your test script tries to validate the layout of your web page.

The API syntax of the getLocation() method is as follows:

Point getLocation()

The preceding method obviously doesn't take any input parameters, but the return type is a Point class that contains the (x, y) coordinates of the element.

The following is the code to retrieve the location of the Search box:

WebElement searchBox = driver.findElement(By.name("q"));
System.out.println("Location of the box is: "
+ searchBox.getLocation());

The output for the preceding code is the (x, y) location of the Search box, as shown in the following screenshot:

Location of the box is: (873, 136)
主站蜘蛛池模板: 沾化县| 延寿县| 惠东县| 临沂市| 清流县| 启东市| 彭泽县| 望奎县| 南和县| 定日县| 鹿邑县| 泰来县| 巩义市| 清河县| 岐山县| 惠安县| 毕节市| 葫芦岛市| 高雄市| 金堂县| 原平市| 古丈县| 囊谦县| 宁都县| 迭部县| 阳原县| 凌云县| 成安县| 沙洋县| 吉木萨尔县| 花垣县| 老河口市| 琼海市| 庄浪县| 云南省| 磐石市| 宽城| 鹤岗市| 尉犁县| 巨鹿县| 科尔|