Selenium IDE:在jquery ui下拉菜单中选择一个href

问题描述:

我使用Selenium IDE和firefox在我的网站上运行测试,当我录制时,我点击列表中的一个项目,它只给我一个动作: Click:css = span.ui-selectmenu-statusSelenium IDE:在jquery ui下拉菜单中选择一个href

我想从列表中选择一个项目,但类和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> 

非常感谢!

+0

啊,好吧,现在你已经发布了html,这是超级压抑。看看你的选择器。我会修改我的回答 –

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

然后,你需要做自己的一些学习上xpath

+0

谢谢你的回应!我要去尝试两种,我会让你知道 –

你的意思是一个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); 
+0

谢谢你的回应!我会尝试两种,我会让你知道 –