小编Man*_*Mkr的帖子

硒获得元素的自然高度和宽度.不应该依赖style属性.GetSize(),GetLocation()和getRect()都无法执行此操作

这是场景.

当我使用GetSize(),GetLocation()函数对图像ID'FlashID1x'时它总是给出250,300,但元素的实际高度和宽度是1 X 1,这基本上是错误的.

这是我的目标dom:

<img id="FlashID1x" border="0" width="300" height="250" style="width:300px;height:250px;" alt="" src="http://s2.adform.net/Banners/invisible.gif?bv=2"/>
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

System.out.println("total : "+iframe.size());  
//driver.switchTo().frame(frame);

org.openqa.selenium.Point point=driver.findElement(By.xpath(".//*[@id='FlashID1x']")).getLocation();  
System.out.println("X Position : "+point.x);  
System.out.println("Y Position : "+point.y);  

System.out.println("X getX : "+point.getX());  
System.out.println("Y gety : "+point.getY());  

Rectangle pointer=driver.findElement(By.xpath(".//*[@id='FlashID1x']")).getRect();
System.out.println("height : "+pointer.hashCode();
System.out.println(" width : "+pointer.getWidth());  

System.out.println("getHeight : "+pointer.getHeight());  
System.out.println(" getWidth : "+pointer.getWidth());  
Run Code Online (Sandbox Code Playgroud)

java selenium selenium-webdriver

7
推荐指数
1
解决办法
8197
查看次数

标签 统计

java ×1

selenium ×1

selenium-webdriver ×1