- 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)
- 連接未來:從古登堡到谷歌的網(wǎng)絡(luò)革命
- 解析QUIC/HTTP3:未來互聯(lián)網(wǎng)的基石
- 萬物互聯(lián):蜂窩物聯(lián)網(wǎng)組網(wǎng)技術(shù)詳解
- 網(wǎng)絡(luò)互聯(lián)技術(shù)(實(shí)踐篇)
- Practical Web Design
- SAE原理與網(wǎng)絡(luò)規(guī)劃
- Learning Windows 8 Game Development
- 物聯(lián)網(wǎng)基礎(chǔ)及應(yīng)用
- Python API Development Fundamentals
- RestKit for iOS
- 物聯(lián)網(wǎng)概論
- 物聯(lián)網(wǎng):感知、傳輸與應(yīng)用
- 網(wǎng)絡(luò)故障現(xiàn)場處理實(shí)踐(第2版)
- 夢工廠之沸騰關(guān)鍵幀:Maya動(dòng)畫手冊
- 區(qū)塊鏈與物聯(lián)網(wǎng):構(gòu)建智慧社會(huì)和數(shù)字化世界