0

How to verify the page source before and after refreshing and how to print the both the page sources

closed as unclear what you're asking by Nitin Rastogi, trashpanda, Niels van Reijmersdal, Milin Patel, Bharat Mane Apr 19 at 7:56

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    What are you trying to verify in the source? – MivaScott Apr 17 at 15:51
  • Hi @MivaScott, There is a checkbox on the left side , on clicking that ,page is refreshing so i want to verify that the page is refreshing or not. so here i'm comparing before and after page source irrespective of elements on the page.if we found any changes on both page source then, we can easily identify the page is refreshed. If have some code for this can u share.. – venkat Apr 18 at 8:29
1

The quick answer is:

String before = driver.getPageSource();
// Do whatever for page refresh
// Make sure there is a delay for the whole page to load
String after = driver.getPageSource();
assertFalse("ERR: Source is the same", after.equals(before));

There are much better ways to do comparisons but you should get the idea.

Comparing the entire source is a very hacky way to check for a refresh. It would be better if you looked for a specific element within the page to change, like a timestamp.

  • Thanks for the clarification and i will try this, – venkat Apr 21 at 16:00

Not the answer you're looking for? Browse other questions tagged or ask your own question.