How to get text from alert box

Hello
I’d like to get the message from the alert box. I have tried the below code, but it only worked for 1 page (no new windows after click button)

Script

@CustomScriptAction(
	output = 'text'
	)

	def customScript() {
		def rtext = switchTo().alert().getText();
		text=RString.of(rtext);
		switchTo().alert().accept();
	}

In the scenario, I’d like to copy the message from the alert box after opening new windows. Please tell me how to modify the code, thanks.
TestMBMS20191213.zip (1.7 KB)
log.txt (10.0 KB)
By the way, I also wrote some python code, it is working for my scenario. Please check the attached file. You can see the result in the video.
https://www.youtube.com/watch?v=iSECHRWodwU&feature=youtu.be

Hello, I found a tricky solution that call refresh() before alert() function.

Script

@CustomScriptAction(
output = 'text'
)
def customScript0002() {
		switchToNextWindow()
		refresh()
		def rtext =  switchTo().alert().getText()
		text=RString.of(rtext);
		switchTo().alert().accept()
}
1 Like

Thank you sharing @PeterLin