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

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)
主站蜘蛛池模板: 益阳市| 永和县| 林甸县| 文安县| 林州市| 渭源县| 临湘市| 桑日县| 克拉玛依市| 东兰县| 错那县| 福清市| 安平县| 固阳县| 平湖市| 柳林县| 信阳市| 枣强县| 东辽县| 乌拉特后旗| 漯河市| 阿拉尔市| 安多县| 盘山县| 哈巴河县| 乐业县| 类乌齐县| 治县。| 临桂县| 黄大仙区| 沐川县| 伊通| 搜索| 五台县| 镶黄旗| 搜索| 尉犁县| 合阳县| 沾益县| 罗平县| 玉山县|