Reputation: 95
I need to find the css selector for the text message : Congratulations! displayed after the registration form is filled successfully by a new user. I am using Selenium Web driver to automate the registration process. I have to assert "Congratulations,Your email has been verified" text. Below is the HTML code for the same :
<div class="d-title">
<h1>Congratulations!</h1>
<strong>Your e-mail address has been verified.</strong>
Thanks, Java Beginner
Upvotes: 1
Views: 2196
Reputation: 14086
Since, Congratulations!
and Your e-mail address has been verified.
are two different texts, you will have to user two different css selectors for them:
For Congratulations!
, use div.d-title > h1
For Your e-mail address has been verified.
, use div.d-title > strong
Upvotes: 0
Reputation: 7018
The below code will wait for 10 seconds and check if the selector contains the provided text, if it doesnt contain, an exception will be thrown...If you want to handle the exception, just surround it with try and catch
new WebDriverWait(driver,10).until(ExpectedConditions.textToBePresentInElement(By.cssSelector("div.d-title>h1"),"Congratulations,Your email has been verified"));
Upvotes: 1
Reputation: 9569
You can't match on text in CSS. You can do it in XPath, but CSS does not have a selector that matches a text node. In XPath, it would be simple: //div/h1[. = 'Congratulations!']
.
Upvotes: 1