2 回答
TA贡献1831条经验 获得超10个赞
你可以试试这个
String selectedList = BrowserFactory.Driver.FindElement(By.XPath("//option[@value='8589934864']")).GetAttribute("value");
或者
String selectedList = BrowserFactory.Driver.FindElement(By.XPath("//option[@value='8589934864']")).GetAttribute("innerText");
TA贡献1817条经验 获得超14个赞
在这里,问题在于您的语法。尝试这个:
try{
selectedList = BrowserFactory.Driver.FindElement(By.XPath("//li[contains(.,'" + listName + "')]/input"));
By.XPath("//li[contains(.,'" + listName + "')]/input"));
//By.XPath("//li[contains(text(),'" + listName + "')]/input")); // you can try this as well
}catch (NoSuchElementException){
selectedList = BrowserFactory.Driver.FindElement(
//By.XPath("//option[contains(.,'" + listName + "')]"); // OR
//By.XPath("//option[contains(text(),'" + listName + "')]");
By.XPath("//option[starts-with(normalize-space(text())='" + listName + "')]")
}
- 2 回答
- 0 关注
- 473 浏览
添加回答
举报