Toast alert capturing


#1

I want to capture text in toast message. as mentioned in the below snapshot toast alert(blue color arrow) is displaying when click on the icon(red color arrow). How to capture that text in the alert.

I tried as below.but unable to make it.

WebUI.click(findTestObject('Datalocker/Databox/DataboxDollarIcon'))
elementPresent=WebUI.waitForAlert(3)
if (elementPresent==true) {
WebDriver driver = DriverFactory.getWebDriver()
String AlertText = driver.switchTo().alert().getText()
println(AlertText)
}else{
print '============'
/*WebUI.verifyEqual(AlertText, 'Success!')
println(AlertText)
WebUI.acceptAlert()*/

#2

This doesn’t look like standard browser alert, so it could be HTML element. Just open a browser console and try to capture it while it is displayed.


#3

Hi @Marek_Melocik…Actullay it is not a HTML element. Thats why i can’t capture it.


#4

Can you share your HTML code of the page with toast message?


#5

Actually it doesn’t have HTML code. It has created using Angular library.(https://www.npmjs.com/package/ng2-toastr)


#6

I get it, but there must be an element, which is displayed as soon as show message function is called. Try to look for an element which contains the message text.


#7

Okay…I’ll try :grinning:


#8

Below code should get the text of the toast message. You just need to capture the correct HTML for the toast message.

WebUI.openBrowser("http://foxandxss.github.io/angular-toastr/")

WebUI.maximizeWindow()

WebUI.click(findTestObject("Page_angular-toastr examples/button_Open Toast"))

KeywordUtil.logInfo( WebUI.getText(findTestObject("Page_angular-toastr examples/div_Success"), FailureHandling.STOP_ON_FAILURE) )

I have used http://foxandxss.github.io/angular-toastr/ website to replicate your toast message. Once the toast message is triggered, html for the same would be added to the DOM. You can use Chropath for getting the correct object to get its XPath.

In my case it was //div[@class='toast-message']