How we can select the value of an <option>
in <select>
by using 'text' in
<option value="123">text<option>
Here is the xpath,by using this i'm able to check that there is a option in <select>
witch contains 'text
'
string xpath = "//*[contains(@name, 'selectname')]/option[contains(translate(text(), " + "'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'text')]";
Here is the html
<select name="selectname">
<option value="`123`">text</option>
<option value="456">text</option>
</select>
I want to get the value 123
by using same xpath which first check that there is a option witch contains some ie 'text' and get the value ie '123'.
var doc = new HtmlAgilityPack.HtmlDocument();
HtmlAgilityPack.HtmlNode.ElementsFlags.Remove("option");
doc.LoadHtml(html);
var values = doc.DocumentNode.SelectNodes("//select[@name='selectname']/option")
.Where(o => o.InnerText=="text")
.Select(o => o.Attributes["value"].Value)
.ToList();