0

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

  • 2
    What are you trying to verify in the source? – MivaScott Apr 17 '19 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 '19 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 '19 at 16:00

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