如何验证元素在视口中是否可见(浏览器的可见性)或不使用Selenium?
我尝试使用下面的代码,但Point对象(Y值)返回巨大的值,因为页面是可滚动的.这里有元素维度,位置和浏览器的维度,并比较它们.
Dimension weD = element.getSize(); //to get the element Dimensions
Point weP = element.getLocation(); // getting the location of the element in the page.
Dimension d = driver.manage().window().getSize(); // To get the browser dimensions
int x = d.getWidth(); //browser width
int y = d.getHeight(); //browser height
int x2 = weD.getWidth() + ewp.getX();
int y2 = weD.getHeight() + ewp.getY();
return x2 <= x && y2 <= y;
Run Code Online (Sandbox Code Playgroud)
如果有人参与其中,你能否分享一下解决方案?