【发布时间】:2019-01-21 13:59:46
【问题描述】:
我想从下拉列表中选择“VxDev:InterAction 测试自动化列表”。代码如下
<select name="intEmailListId" id="intEmailListId" style="min-width: 210px" data-selected-list="8589934864" class="list_selector">
<option value="">** Please select a list **</option>
<option value="">
--
</option>
<option value="my-contacts">
My contacts
</option>
<option value="">
--
</option>
<option value="8589934952">
* 001 New List
</option>
<option value="8589934880">
VxDev: Hard Bounce List (QA team only)
</option>
<option value="8589934864" selected="">
VxDev: InterAction Test Automation List
</option>
我在xpath下面试过,以前可以用,现在不行了
try
{
selectedList =
BrowserFactory.Driver.FindElement(
By.XPath(".//li[text()[contains(.,'" + listName + "')]]/input"));
}
catch (NoSuchElementException)
{
selectedList = BrowserFactory.Driver.FindElement(
//By.XPath(".//option[text()[contains(.,'" + listName + "')]]"));
By.XPath(".//option[starts-with(normalize-space(text()),'" + listName + "')]"));
}
请帮助如何选择具体的下拉值?提前致谢。
【问题讨论】:
-
也许使用 css 选择器代替....By.Selector("#intEmailListId > option[value='8589934864']")...你需要点击它然后...你可以也使用 SelectElement selectElement = new SelectElement(.By.Selector("#intEmailListId > option[value='8589934864']")) 然后执行 selectElement.SelectByText("drop down visible Text here") 或 selectElement.SelectByValue( “此处选项的值”)或 selectElement.SelectByIndex(此处的选项索引)
-
你说的“现在不工作”是什么意思?运行代码时会发生什么?
-
当我运行代码时,脚本正在超时。当我使用上述 xpath 手动检查元素时,Chrome 中没有选择列表元素
-
@Tanya,加
selectedList.Click(); -
请花一点时间来修正 HTML 的缩进。网络上有很多 HTML 美化器可以帮助实现这一点。还要修正代码的缩进,使其更易于阅读。您需要发布完整的(相关的)错误消息。
标签: c# selenium-webdriver