I am trying to run a TEST in TESNG and i want to know if a popup with a specific text is thrown in screen.
I'm kinda new to Selenium and JAVA
When i click on a button an action is performed and if it went alright i got this message (this is the element):
<div role="alert"><span>Company.-007989 has been approved</span><button type="button" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button></div>
In this case Company.-007989
varies depending on the customer.
How can i do to store the message somehow to see if my TEST run alright?.
I want to know if i got some popup within the text "has been approved"
. Is there any way?
I tried to store the popup message but nothing really worked
CodePudding user response:
As per the HTML code you have shared of your popup, your success message resides in span
tag so you should target span with the help of xpath. You can create custom xpath as well, in your case //div[@role="alert"]/span
should work.
CodePudding user response:
Try if this code works:
// Find popup by xpath:
@FindBy(xpath = "//div[@role="alert" and contains(text(),'has been approved')]") WebElement popupAlertText;
// Wait till popup alert is displayed:
WebDriverWait wait = new WebDriverWait(seleniumDriver, Duration.ofSeconds(1000));
wait.until(ExpectedConditions.visibilityOf(popupAlertText));
// Get the value shown in the popup message and store in a string:
String popupAlertTextValue = popupAlertText.getAttribute("span");