量角器 - 由于固定的顶部导航栏,无法访问元素



我在茉莉花量角器中面临以下问题

单击/鼠标悬停不起作用,因为在我的应用程序中固定了顶部导航栏。我需要在网页上单击/执行鼠标悬停。 不幸的是,该元素显示在固定导航栏后面。因此,滚动直到元素存在并按x和y坐标单击不起作用。

我的依赖项是:

量角器版本 5.2.2

节点 8.9.3

硒独立 3.13

铬驱动程序-2.40

浏览器 v67

操作系统 - 视窗 10

提前致谢

尝试使用 prototype executeScript

只需尝试使用 id、name 或 xpath 从浏览器控制台单击该元素即可。

例如:

var el = element(by.module('header'));
var tag = browser.executeScript('return arguments[0].click()', el).then(function() {
expect(something).toMatch(something);
});

另一种方式,与 Bharath Kumar S 的思路相同,并且知道 JeffC 的警告,即这种方法是作弊,我遇到了类似的问题,应用程序标头不断妨碍我点击,我知道我愿意永远不需要它(因此,例如,找到其他导航或注销的方法,而不是检查上面的东西(。因此,我做了以下工作,解决了问题。请注意,如果刷新屏幕,则必须再次调用它。另请注意,我正在使用 https://github.com/hetznercloud/protractor-test-helper 中的许多函数,这些函数可以满足您对它们名称的期望。

var removeAppHeaderIfAny = async function() {
//this function hides the app header
//it is useful to avoid having covers there when Protractor worries that something else will get the click
let found = false;
try {
found = await waitToBeDisplayed(by.className("app-header"), 2000);
} catch (e) {
let s: string = "" + e;
if (s.search("TimeoutError") != 0) flowLog("presumably fine, cover already removed: " + e);
found = false;
}
if (!found) return;
if (found) {
let coverElement = await element(by.className("app-header"));
browser.executeScript(
"arguments[0].style.visibility='hidden';",
coverElement
);
await waitToBeNotDisplayed(by.className("app-header"), 10000);
}
return;
//note after this is called you will not see the item, so you cannot click it
};

当我查看代码时,我突然想到,人们可能会删除末尾的 if(找到(和相关括号。但是我粘贴了一些我知道一直在工作的东西,所以我不会搞砸它。

如前所述,我知道我愿意放弃使用应用程序标题,这有点粗糙。

最新更新