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

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)
主站蜘蛛池模板: 甘肃省| 江都市| 长阳| 林甸县| 临安市| 娱乐| 云林县| 临汾市| 页游| 彝良县| 东山县| 密山市| 奉节县| 太仓市| 门源| 饶平县| 西乌珠穆沁旗| 即墨市| 太谷县| 鹤壁市| 明光市| 乐至县| 淳安县| 武冈市| 新源县| 淮阳县| 图木舒克市| 铜川市| 宿州市| 奉新县| 遵义市| 靖远县| 星子县| 余江县| 景德镇市| 镇远县| 陇川县| 庄浪县| 合川市| 尼木县| 呼玛县|