我有一个DROPDOWN LIST,它没有select属性:
<ul id="Registration_RegistrationStateCode_listbox" class="k-list k-reset" unselectable="on" style="overflow: auto; height: 200px;" tabindex="-1" role="listbox" aria-hidden="false" aria-live="off">
<li id="Registration_RegistrationStateCode_option_selected" class="k-item k-state-selected k-state-focused" unselectable="on" role="option" tabindex="-1" aria-selected="true">-- Select State --</li>
<li class="k-item" unselectable="on" role="option" tabindex="-1">Alabama</li>
<li class="k-item" unselectable="on" role="option" tabindex="-1">Alaska</li>
<li class="k-item" unselectable="on" role="option" tabindex="-1">Arizona</li>
<li class="k-item" unselectable="on" role="option" tabindex="-1">Arkansas</li>
<li class="k-item" unselectable="on" role="option" tabindex="-1">California</li>
<li class="k-item" unselectable="on" role="option" tabindex="-1">Colorado</li>
如何选择特定的州?
我无法选择任何状态,因为它没有选择标记。
答案 0 :(得分:3)
如果你使用Page Object Model,我会在这个特定的Page Object中创建一个函数,如下所示:
public void SelectState(string state)
{
_driver.FindElement(By.Id("Registration_RegistrationStateCode_listbox")).Click();
_driver.FindElement(By.XPath("//li[text()='" + state + "']")).Click();
}
否则你可以使用单独的行并传入一个状态:
_driver.FindElement(By.Id("Registration_RegistrationStateCode_listbox")).Click();
_driver.FindElement(By.XPath("//li[text()='Minnesota']")).Click();