0

I have a form. I automated the task of filling up the form and clicking the submit button using Selenium WebDriver.

Now in the next page where the URL has changed, there is a confirmation message "Form Submitted Successfully". How do I verify this element in the new URL?

Thanks in advance!

3
  • If you need a better answer i will need more info, but you can ask your webdriver to find a element that you know will be in that new url or you can get the current url like webdriver.getCurrentUrl(), now you need to wait for the new page to be loaded. Commented Mar 14, 2016 at 20:23
  • Is the confirmation in an Alert box;, i.e. do you have to click OK? Is the confirmation in its own iFrame? Is the confirmation part of the next web page that is displayed? As acardose said, you need to supply more information. Commented Mar 14, 2016 at 20:53
  • The confirmation part of the next web page that is displayed. It is located inside a <div> element. I figured it how and it works fine now. I used the WebDriver() to locate this element and got its contents thru getText() method. Thank you all for your inputs! Commented Mar 14, 2016 at 21:49

2 Answers 2

1

Try to use JUnit assertion to compare expected string with actual the one you getting on the page, this should work :

String actual = driver.findElement(By.xpath("your_locator").getText();
Assert.assertEquals(actual, expected);
Sign up to request clarification or add additional context in comments.

Comments

0

As per my knowledge, even if the objects you are working on are on different page(url) it does not matter, you just need to have your locator correctly written.

Using getText() method you could get text on the page. Verify whether your locator is pointing to correct text using xpath validaters or other means.

Once you have your locator handy apply getText() method on it and get the text.

Once you have text, just verify it or print it to see if it is the same.

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.