Selenium WebDriver无耻地返回错误的WebElement高度 [英] Selenium WebDriver Shamelessly Returns Incorrect Height of WebElement

查看:111
本文介绍了Selenium WebDriver无耻地返回错误的WebElement高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在此页面上使用Selenium Firefox WebDriver捕获WebElement的快照:.//*[@id='aplus']/div: https://www.amazon.com/dp/B07G9RZD14

当我使用Chrome浏览器检查元素时,会得到以下尺寸: 979.2 x 1961.6

但是,当调用element.getSize().getWidth()element.getSize().getHeight()时,我得到 979 (宽度)和 1461 (高度).因此,宽度与 Chrome Inspector 检索到的值匹配,但高度相差数百个点(准确地说是500个点). WebDriver返回错误的高度而不会感到羞耻.

此外,当我截取实际元素的屏幕截图时,该元素的 height 部分实际上并未被捕获,因此Chrome返回的值似乎是正确的.

我尝试检索自然高度和宽度"如此线程中通过getAttribute()JS所建议的那样,但在两种情况下,它仅返回NULL. /p>

为什么WebDriver返回错误的高度,如何获取正确的值?

谢谢

解决方案

我进一步研究了这种现象,结果发现浏览器的大小并不是造成此问题的原因.我总是以最大化模式运行浏览器.事实证明,存在一个扩展器".导致元素在滚动到视图中后增长的HTML代码中的函数. 主题是一个新问题这个问题我在SO上发布了.

I'm trying to capture snaptshot of WebElement: .//*[@id='aplus']/div using Selenium Firefox WebDriver on this page: https://www.amazon.com/dp/B07G9RZD14

When I inspect element using Chrome I get the following dimensions: 979.2 by 1961.6

However, when calling element.getSize().getWidth() and element.getSize().getHeight() I get 979 (width) and 1461 (height). So the width matches the value retrieved by Chrome Inspector but the height is off by several hundred points (500 to be exact). WebDriver is returning the wrong height without being ashamed of it.

Moreover, when I take a screenshot of the actual element it seems that part of the height of the element is in fact not being captured so the value returned by Chrome seems to be the correct one.

I tried retrieving the "natural height and width" as suggested in this thread via getAttribute() and through JS but in both cases it just returns NULL.

Why is WebDriver returning the wrong height and how can I get it to return the correct value?

Thanks

解决方案

I investigated this phenomenon further and it turns out that the size of the browser was NOT the cause of this problem. I always ran browser in maximized mode. It turns out there is an "expander" function in the HTML code that caused the element to grow after it is scrolled into view. How this works is the subject a new question I posted on SO.

这篇关于Selenium WebDriver无耻地返回错误的WebElement高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆