上QQ阅读APP看书,第一时间看更新
The getSize() method
The getSize method can also be called on all the visible components of HTML. It will return the width and height of the rendered WebElement. The API syntax of the getSize() method is as follows:
Dimension getSize()
The preceding method doesn't take any input parameters, and the return type is a class instance named Dimension. This class contains the width and height of the target WebElement. The following is the code to get the width and height of the Search box:
WebElement searchBox = driver.findElement(By.name("q"));
System.out.println("Size of the box is: "
+ searchBox.getSize());
The output for the preceding code is the width and height of the Search box, as shown in the following screenshot:
Size of the box is: (281, 40)