作为一个注释,这些测试似乎在其他机器上运行良好,唯一的区别是测试失败的操作系统是Windows 10?
有人知道量角器/硒如何确定元件的位置.
提前致谢.
杰克·里夫斯
编辑:
评论后请求一些例子:
- browser.get('examplePageAddress')
- var elem = element.all(by.className('header')).get(0)
- var div = elem.element(by.name('examplename'))
获取实际的按钮
- var button = element(by.name('exampleButtonName'))
在实际测试中,一个简单的button.click()被调用,这是什么缺少按钮约50px.
通过调试和写入控制台,我已经确认选择了正确的元素[使用.getInnerHTML()],并通过测量按钮的位置确定它大约为50px不同[使用.getLocation()来确定x和y返回的量角器]
In the actual test a simple button.click() is called and that is what is missing the button by about 50px
在这种情况下,首先移动到元素,然后执行点击:
- browser.actions().mouseMove(button).click().perform();
或者,scroll into view的元素:
- browser.executeScript("arguments[0].scrollIntoView();",button.getWebElement());
- button.click();
请注意,getLocation()本身取决于可见区域 – 浏览器确定的视口.在不同的浏览器和不同的操作系统中可能会有所不同.也可以看看:
> WebElement.getLocation and WebElement.getSize in screen shots
而且,您可以实际获取视口大小并将其与执行测试的浏览器和系统进行比较 – 我确定您将获得不同的值,请参阅:
> Get the browser viewport dimensions with JavaScript
您还可以查看getBoundingClientRect()
在您的情况下的回报:
The
Element.getBoundingClientRect()
method returns the size of an element and its position relative to the viewport.
- browser.executeScript("return arguments[0].getBoundingClientRect();",button.getWebElement()).then(function (rect) {
- console.log(rect.left);
- console.log(rect.top);
- });