Reputation: 1136
I have having trouble getting my specific string from an ordered list. I am using C# and Visual Studio to search a website for a specific string to then import into an Excel sheet. Specifically, this value needs to be a birthdate. My current request for the string is as follows:
driver.FindElement(By.XPath("//*[contains(text(), 'Birthdate')]")).Text;
The Ordered list that I am searching through is as follows:
<ol>
<li>
<label>Name</label>Humphries, Ryan</li>
<li>
<label>Birthdate</label>11/14/1992</li>
<li>
<label>SSN</label>
I can search for 'Birthdate' and I get that string to return to my document with my current code, however, I want the actual birthdate, not the label.
Upvotes: 3
Views: 361
Reputation: 473753
The problem is, you cannot find/refer to a text node with selenium directly. The common way to approach this problem is to get the text of the parent element and "subtract" the child element's text from it.
In other words, find the li
element, get the text and replace Birthdate
with an empty string:
driver.FindElement(By.XPath("//li[label = 'Birthdate']")).Text.Replace("Birthdate", "")
Upvotes: 3