[英]JQuery UI select Item from dropdown Selenium c#
I am new to Selenium and I need to test a page that uses JqueryUI extensivily. 我是Selenium的新手,我需要测试一个使用JqueryUI的页面。
to take an example everyone can work on Let's have a look at http://view.jqueryui.com/master/demos/selectmenu/default.html page 举一个例子,每个人都可以参与进来让我们来看看http://view.jqueryui.com/master/demos/selectmenu/default.html页面
now from the "Select a speed" dropdown i want to select "Fast" 现在从“选择速度”下拉列表我想选择“快速”
My understading is that at runtime jqueryUI makes the following code not visible and creates "UL-LI" therefore the "SelectElement" function cannot be used. 我的理解是,在运行时,jqueryUI使以下代码不可见并创建“UL-LI”,因此不能使用“SelectElement”函数。
View Source=
<label for="speed">Select a speed</label>
<select name="speed" id="speed">
<option>Slower</option>
<option>Slow</option>
<option selected="selected">Medium</option>
<option>Fast</option>
<option>Faster</option>
</select>
Runtime "Inspect element" you get:
<div class="ui-selectmenu-menu ui-front ui-selectmenu-open" style="top: 94.5938px; left: 22px;">
<ul aria-hidden="false" aria-labelledby="speed-button" id="speed-menu" role="listbox" tabindex="0"
class="ui-menu ui-corner-bottom ui-widget ui-widget-content" aria-activedescendant="ui-id-26" aria-disabled="false" style="width: 256px;">
<li class="ui-menu-item">
<div id="ui-id-26" tabindex="-1" role="option" class="ui-menu-item-wrapper ui-state-active">Slower</div>
</li>
<li class="ui-menu-item">
<div id="ui-id-27" tabindex="-1" role="option" class="ui-menu-item-wrapper">Slow</div>
</li>
<li class="ui-menu-item"><div id="ui-id-28" tabindex="-1" role="option" class="ui-menu-item-wrapper">Medium</div></li>
<li class="ui-menu-item"><div id="ui-id-29" tabindex="-1" role="option" class="ui-menu-item-wrapper">Fast</div>
</li><li class="ui-menu-item"><div id="ui-id-30" tabindex="-1" role="option" class="ui-menu-item-wrapper">Faster</div>
</li>
</ul>
</div>
What I would like to do is 我想做的是
How do I do this? 我该怎么做呢? I did find an link that with a solution to my same problem but I cannot make it work in c# https://groups.google.com/forum/#!msg/selenium-users/uWmH_XuxcPM/2GVQnHd2aLIJ 我确实找到了一个解决我同样问题的链接,但我无法在c# https://groups.google.com/forum/#!msg/selenium-users/uWmH_XuxcPM/2GVQnHd2aLIJ
Can you help? 你能帮我吗? Thanks 谢谢
As you have mentioned todos. 正如你所提到的待办事项。 Following code will help you to accomplish the same- 以下代码将帮助您完成相同的事情 -
First you need to click on speed-dropdown span
only then it loads the ul
and li
tags - 首先,您需要点击速度下拉span
然后才会加载ul
和li
标签 -
driver.FindElement(By.Id("speed-button")).Click();
Then get all li
tags of speed-menu
然后获取speed-menu
所有li
标签
IList<IWebElement> menuElements = driver.FindElements(By.XPath("//ul[@id='speed-menu']/li"));
And iterate all element, find your match and select that one - 迭代所有元素,找到你的匹配并选择那个 -
foreach (IWebElement element in menuElements )
{
string value= element.FindElement(By.TagName("div")).Text;
if(value.Equals("Faster"))
{
element.Click();
}
}
Note :- Please check syntax as per C#
注意: - 请按照C#
检查语法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.