سؤال

How to find the Xpath or Id for Alert ? On clicking the Save button, Alert popup displayed on the Screen. I'm unable to find the xpath or id for the Alert using the developer tool.

And, How to take the Text from Alert ?

Thanks, Thyagu

هل كانت مفيدة؟

المحلول

You can retrieve the text from Alert using below code

String alertMessage = driver.switchTo().alert().getText();
System.out.print(alertMessage);

نصائح أخرى

You can not, as it is not in the html. However you can handle alert using following code:

driver.switchTo().alert().accept();

It is unable to find x-path or id for an alert. you can only click on alert. To accept or dismiss alert you can use switchTo() method.

  driver.switchTo().alert().accept();
  driver.switchTo().alert().dismiss();
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top