I am opening a mail in an inbox and grab a url from the open mail content, which I want to use for further actions. The url to be used could be only one of the above css elements( from different mails)
**Here is the Code block:**
if (getDriver().findElement(By.css("body > p:nth-child(5)")) != null)
{
String URL = getDriver().findElement(By.css("body > p:nth- child(5)")).getText();
} else {
String mailBody = getDriver().findElement(By.css("body > p:nth-child(2)")).getText();
String[] temp = mailBody.split("\n");
String URL = temp[2];
System.out.println(URL);
}
String resetLink = URL;
System.out.println(resetLink);
getDriver().get(resetLink);
Here for me the script is failing to locate the element with below error (it is in one way is correct because the required url can be grabbed by the 'else' part of the code.
NoSuchWebElementException: Unable to locate element: By[method = css, selector = "body > p:nth-child(5)"]
I was expecting to first run the 'if' statement to check for Url , if it is not there, then I want the 'else' statement to be run and then grab the Url from the mail body.
Please help me by pointing where am I making mistake. Thank you for any of your suggestions. regards,
Aucun commentaire:
Enregistrer un commentaire