- Selenium WebDriver 3 Practical Guide
- Unmesh Gundecha Satya Avasarala
- 174字
- 2021-08-13 16:08:10
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)
- EJB 3.1從入門到精通
- Building E-commerce Sites with VirtueMart Cookbook
- Learning Karaf Cellar
- 無人機通信
- 正在爆發(fā)的互聯(lián)網(wǎng)革命
- Metasploit Penetration Testing Cookbook
- Learning Swift(Second Edition)
- 搶占下一個智能風口:移動物聯(lián)網(wǎng)
- 新手易學:新手學淘寶開店
- 網(wǎng)絡設計與應用(第2版)
- 網(wǎng)管第一課:網(wǎng)絡操作系統(tǒng)與配置管理
- 從實踐中學習手機抓包與數(shù)據(jù)分析
- Hands-On Microservices with Node.js
- 云工廠:開啟中國制造云時代
- 5G非正交多址接入技術:理論、算法與實現(xiàn)