【问题标题】:Selenium IDE : Select an href in a jquery ui dropdown menuSelenium IDE:在 jquery ui 下拉菜单中选择一个 href
【发布时间】:2012-06-18 23:45:22
【问题描述】:

我正在使用 Selenium IDE 和 firefox 在我的网站上运行测试,当我录制并单击列表中的一个项目时,它只会给我一个操作: 点击:css=span.ui-selectmenu-status

我想从列表中选择一个项目,但类和 ID 是动态加载的,因为该站点在此处使用 JQUERY UI 运行。

我正在尝试:

点击://div[@id='hlevel-menu']/a[.='CATS']

但它返回一个错误:未找到..

我猜这是错误的或超级错误的,如果有人知道怎么做,请帮助:)

这是我正在寻找的代码部分:

<div class="dceui ui-selectmenu-menu ui-selectmenu-open" style="z-index: 1; top: 363px; left: 699.5px;">

    <ul id="hlevel-menu" class="ui-widget ui-widget-content ui-selectmenu-menu-dropdown ui-corner-bottom bg_education_icon" aria-hidden="false" role="listbox" aria-labelledby="hlevel-button" style="width: 121px; height: auto;" aria-disabled="false" aria-activedescendant="ui-selectmenu-item-331">

    <li class="" role="presentation">
        <a id="" href="#nogo" tabindex="-1" role="option" aria-selected="false">- Please choose -</a>
    </li>

    <li class="" role="presentation">
        <a href="#nogo" tabindex="-1" role="option" aria-selected="false">DOGS</a>
    </li>

    <li class="" role="presentation">
        <a id="" href="#nogo" tabindex="-1" role="option" aria-selected="false">CATS</a>
    </li>

    <li class="ui-corner-bottom ui-selectmenu-item-selected" role="presentation">
        <a href="#nogo" tabindex="-1" role="option" aria-selected="true" id="ui-selectmenu-item-331">PIGS</a>
    </li>
</div>

非常感谢!

【问题讨论】:

  • 啊,好吧,现在你终于发布了 html,这真是太令人沮丧了。看看你的选择器。我会修改我的答案

标签: jquery user-interface drop-down-menu selenium ide


【解决方案1】:

您的意思是 jQuery 自动完成功能吗?还是普通类型的下拉菜单?

这就是我在 selenium 中选择自动完成列表值的方式:(注意这是输入代码,而不是记录代码)。这有点棘手,你必须让它触发自动完成,然后你必须突出显示值,然后你必须选择它。

string locator = "id=hlevel-menu";
string value = "CATS";
selenium.Focus(locator);
selenium.Type(locator, value);
selenium.KeyDown(locator, "\\40");
Thread.Sleep(50);
selenium.KeyDown(locator, "\\40");
Thread.Sleep(50);
selenium.KeyDown(locator, "\\13");
Thread.Sleep(50);

【讨论】:

  • 感谢您的回复!我要两个都试一下,我会告诉你的
【解决方案2】:

它不起作用,因为//div/a 正在寻找直系后代,而不是子孩子中任何地方的所有标签。你需要做//div/ul/li/a[text()='CATS']

那你需要在xpath上自己学习一下

【讨论】:

  • 感谢您的回复!我要两个都试一下,我会告诉你的
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-13
  • 2022-01-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多