简体   繁体   English

WebdriverJS和下拉菜单

[英]WebdriverJS and drop down menus

I am running WebdriverJS on nodeJS to test the UI of a website. 我在nodeJS上运行WebdriverJS以测试网站的UI。 I want select and click on a submenu item in a drop down menubar. 我要选择并单击下拉菜单栏中的子菜单项。 The submenu items are hidden by CSS. 子菜单项被CSS隐藏。 The menubar looks like this: 菜单栏如下所示:

<ul class="dropdown" id="mainNavList">
    <li class="active"> 
        <a href="/home"><span>Home</span></a>
    </li>
    <li class="">
        <a href="/MyProducts"><span>My Products</span></a>
        <ul style="visibility: hidden;">
            <li class="">
                <a href="/uiuiu">Product A</a>
            </li>
            <li class="">
                <a href="/jkjkjk">Product B</a>
            </li>
        </ul>
    </li>

    <li>...</li>

</ul>

If I try to run this approach: 如果我尝试运行此方法:

mydriver.executeScript("return $(\"a:contains('My Products')\").mouseover();").then(function(){
mydriver.findElement(mywebdriver.By.xpath("//a[contains(text(), 'Product B')]")).click();
        });

the drop down slides down but hides directly after showing it. 下拉列表向下滑动,但显示后直接隐藏。 On the console I get an error from Webdriver: 在控制台上,我从Webdriver收到错误消息:

ElementNotVisibleError: Element must be displayed to click (WARNING: The server did not provide any stacktrace information)

Any ideas? 有任何想法吗?

这对我来说也是新手,但是我会链接“单击”下拉菜单中的函数调用,然后单击所需的下拉菜单项。

try this: 尝试这个:

var menu = mydriver.findElement(mywebdriver.By.css('[href="/MyProducts"]'));
menu.click();
menu.findElement(mywebdriver.By.css('[href="/jkjkjk"]')).click();

As James said it's about chaining. 正如詹姆斯所说,这是关于连锁的。 In the snippet above the chaining is implicit (both findElement and click methods add a frame to the webdriver.controlFlow() . 在上面的代码段中,链接是隐式的(findElement和click方法都将一个框架添加到webdriver.controlFlow()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM