Reputation: 162
I want to select this particular text "Password field is required." , which is apparently inside the <span>
tag.
<span id="password" class>
::before
"Password field is required."
</span>
I tried to find the element using the Id
but unfortunately it doesn't seem to work. My code is like this :
var emptyPassword = WebBrowser.Current.FindElement(By.Id("password"));
Assert.AreEqual("Password field is required.", emptyPassword);
I also tried using Xpath
but still no luck. The Xpath
look like this:
//*[@id="password"]
Can somebody explain to me why i can't locate the element using Id or xpath? thanks :)
Upvotes: 0
Views: 1572
Reputation: 151391
With the HTML you show and the code you show Selenium should be able to find your element. However, you are not asserting that its text is the value you want so perform the assertion like this:
Assert.AreEqual("Password field is required.", emptyPassword.Text);
Note the added .Text
at the end, which gets the text of the element. What FindElement
returns is a WebElement
object, not a string.
Upvotes: 1
Reputation: 16201
Do a text based search.
.//*[.='Password field is required.']
by . you are pointing to parent element here.
Upvotes: 0