我正在使用webdriverJS在selenium中创建一个自动调试的测试脚本。( node.js approach )
我有一些菜单和子菜单。
我正在尝试点击可折叠按钮,该按钮会打开菜单栏。在每个菜单下,都有一些子菜单。
我有一个类似
的数组minorSize = (
0 => ,
1 => ,
2 => 7,
3 => 3,
4 => 5,
5 => 8,
6 => 4,
7 => 3)
哪里
menu <li[2]> has 7 submenu,
menu <li[3]> has 3 submenu,
menu <li[4]> has 5 submenu,
menu <li[5]> has 8 submenu,
menu <li[6]> has 4 submenu,
menu <li[7]> has 3 submenu
以下是通过每个菜单和子菜单访问的递归函数。
function clickMenu(iMajor, majorLinkLast,iMinor)
{
driver.wait(until.elementIsVisible(driver.findElement(By.xpath("//a[contains(@class, 'navbar-minimalize minimalize-styl-2')]"))));
driver.findElement(By.xpath("//a[contains(@class, 'navbar-minimalize minimalize-styl-2')]")).click().then((function(iMajor,majorLinkLast,iMinor){
driver.wait(until.elementIsVisible(driver.findElement(By.id('side-menu'))));
(function(iMajor,majorLinkLast,iMinor)
{
majorMenuXPath = "//ul[contains(@id, 'side-menu')]/li["+iMajor+"]/a";
driver.findElement(By.xpath(majorMenuXPath)).click().then((function(iMajor,majorLinkLast,iMinor){
minorMenuXPath = "//ul[contains(@id, 'side-menu')]/li["+iMajor+"]/ul/li["+iMinor+"]/a";
driver.wait(until.elementIsVisible(driver.findElement(By.xpath(minorMenuXPath))));
driver.findElement(By.xpath(minorMenuXPath)).click().then((function(iMajor,majorLinkLast,iMinor)
{
console.log(iMajor+" "+ minorSize[iMajor]+" "+iMinor);
iMinor = parseInt(parseInt(iMinor) + 1)
if(iMinor <= minorSize[iMajor])
{
/*driver.getTitle().then(function(title)
{
console.log(title);
});*/
clickMenu(iMajor,majorLinkLast,iMinor);
}
else
{
if(iMajor < majorLinkLast)
{
iMajor = parseInt(parseInt(iMajor) + 1)
clickMenu(iMajor,majorLinkLast,1);
}
}
})(iMajor,majorLinkLast,iMinor));
})(iMajor,majorLinkLast,iMinor));
})(iMajor,majorLinkLast,iMinor);
})(iMajor,majorLinkLast,iMinor));
}
以这种方式从测试服中调用该函数。
majorLinkLast = parseInt(majorLinkSize + 1);
var iMajor = 2;
clickMenu(iMajor,majorLinkLast,1);
在菜单上单击三次(三个子菜单)后,脚本会抛出一个 “ ElementNotVisibleError:元素不可见”例外。
有什么方法可以让我知道哪个特定元素确实导致异常?一些日志功能或方法?
以下是例外报告:
ElementNotVisibleError: element not visible
(Session info: chrome=45.0.2454.101)
(Driver info: chromedriver=2.19.346078
(6f1f0cde889532d48ce8242342d0b84f94b114
1),platform=Windows NT 5.1 SP3 x86)
at Array.forEach (native)
From: Task: TrackRevenue Click Menu Test View page by clicking menu
答案 0 :(得分:0)
点击后子菜单链接是否关闭了子菜单?
如果这样做,您必须在点击新的子菜单链接之前触发单击父菜单链接(打开子菜单的链接)。