2

I'm using selenium webdrive in c# for learning and writing automated tests and i have come across this situation:

Say you have a website like this: http://referencewebapp.qaautomation.net/register.php and you get the pop-up with the error message as a javascript alert(if you press Register without filling in any info, for example). What i need to do is to check what error message (the text) is in the alert.

I cannot use driver.FindElement or drive.PageSource as i cannot see the source code for it. I read about trying to select/change the frame(Selenium cannot get alert thrown in iframe), but i don't know how the frameID. Is there any way i can find and check that text?

Thanks for any suggestions.

2 Answers 2

2
 driver.SwitchTo().Alert().Text;

should be all you need.

Sign up to request clarification or add additional context in comments.

Comments

1

You can try to get the text of an alert (dialog) by using selenium Alert object.

for example:

    Alert alert = driver.switchTo().alert();
    String alertText = alert.getText();
    if (alertText.equals("error...")) {

        // Do Something...

        // dismiss alert
        alert.dismiss();

    }

More information in the selenium 2.0 documentation.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.