The text "Congratulations!" apprears on the site only when the transaction is successful.
I am trying to capture the text of this element using JavascriptExecutor as the type is set to hidden but selenium always displays:
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//div[@class='form-header']//div[contains(text(),'Congratulations')]"}
(Session info: chrome=85.0.4183.121)
Code 1 (Not Working)
WebElement ele = driver.findElement(By.xpath(//div[@class='form-header']//div[contains(text(),'Congratulations')]));
JavascriptExecutor js = (JavascriptExecutor)driver;
String text = (String)js.executeScript("return arguments[0].value",ele);
System.out.println(text);
Code 2 (Not Working)
WebElement ele = driver.findElement(By.xpath(//div[@class='form-header']//div[contains(text(),'Congratulations')]));
JavascriptExecutor js = (JavascriptExecutor)driver;
String text = (String)js.executeScript("return arguments[0].innerHTML",ele);
System.out.println(text);
The HTML code for this part is as follows:
<input id="hdnWindowLocationHost" name="hdnWindowLocationHost" type="hidden" value="/" data-value="themes/custom">
<div id="sgw" class="sgw SGW-header">
</div>
<div class="page">
<div class="content">
<div class="form">
<div class="form-header">
<div class="headline">Congratulations!</div>
Your password has been reset. Please log in below with your Username and password.
</div>