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

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)
主站蜘蛛池模板: 京山县| 建宁县| 鄂州市| 平潭县| 永善县| 宁南县| 安仁县| 大港区| 南宫市| 新田县| 玉龙| 天长市| 壶关县| 开原市| 四会市| 民和| 井陉县| 会宁县| 团风县| 益阳市| 阿坝县| 波密县| 富川| 文安县| 舞阳县| 湘乡市| 阿尔山市| 乌鲁木齐市| 电白县| 三台县| 来宾市| 台州市| 湛江市| 闸北区| 卓尼县| 额尔古纳市| 织金县| 萨嘎县| 正阳县| 瑞金市| 四子王旗|