无法单击selenium webdriver中的子菜单

时间:2014-07-31 07:17:16

标签: selenium-webdriver

鼠标悬停菜单不起作用。请参阅以下详细信息: -

  1. 点击开始时 - >我得到了子菜单。

  2. 点击客户子菜单时 - >元素不可点击

  3. 一个。我应该可以去“搜索客户”或“创建顶级客户”

    <div class="TidyMenu Horizontal" id="mainNav">
        <ul class="level1">
            <li><a class="popout level1" href="#" onclick="__doPostBack(&#39;ctl00$mainNav&#39;,&#39;Start&#39;)">Start</a>
                <ul class="level2">
                    <li><a class="popout level2" href="#" onclick="__doPostBack(&#39;ctl00$mainNav&#39;,&#39;Start\\Customers&#39;)">Customers</a>
                        <ul class="level3">
                            <li><a title="Search for Customers" class="level3" href="#" onclick="__doPostBack(&#39;ctl00$mainNav&#39;,&#39;Start\\Customers\\3&#39;)">Search for Customers</a></li>
                            <li><a title="Create Top level Customer" class="level3" href="#" onclick="__doPostBack(&#39;ctl00$mainNav&#39;,&#39;Start\\Customers\\8&#39;)">Create Top level Customer</a></li>
                        </ul>
                    </li>
                </ul>
            </li>
    <div>
    

2 个答案:

答案 0 :(得分:0)

使用动作实用程序将鼠标悬停在开始上,然后单击所需的子菜单。示例代码应如下所示:

using OpenQA.Selenium;
using OpenQA.Selenium.Interactions;
using OpenQA.Selenium.Interactions.Internal;
using OpenQA.Selenium.Support.UI;

//create Actions object
Actions builder = new Actions(driver);
IWebElement menuHoverLink = driver.FindElement(By.XPath("//a[text()='Start']"));
builder.MoveToElement(menuHoverLink);

IWebElement subLink = driver.FindElement(By.LinkText("Customers"));
builder.MoveToElement(subLink);
builder.Click();
builder.Build().Perform();

Lemme知道这是否有帮助!

答案 1 :(得分:0)

我们可以使用键移动并单击,而不是使用鼠标坐标来尝试键盘。

请试试这个

Mousehover:

String hover=Keys.chord(Keys.DOWN);
driver.findElement(By.linkText("the text which has to be clicked")).sendKeys(hover);

点击:

String clickdown=Keys.chord(Keys.ENTER);
driver.findElement(By.linkText("sub menu which has to be clicked")).sendKeys(clickdown);