Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium: how to ensure back() navigation works as expected across different sites?

So I am concerned with

webdriver.navigate().back();

in particular. AFter reading How does the Back button in a web browser work?

it made me think of how can I make sure back button behaves as expected?

Here's different ways of having "back" navigation. How would you go about detecting which approach to use? Listen to whether POST or GET is being made? Listen for AJAX requests and plan the appropriate plan?

a) navigate back() (essentially hitting back button in firefox)
b) make GET request to the previous page url
c) click on "return to results" on current page

with a) back() sometimes do not work correctly for AJAX sites with no breadcrumbs. or for POST search results for example where pressing back will prompt alert message.

with b) my concern is that the url may not match up,

ex) dynamic urls with unique hash sessionid parameters

http://www.aa.com/results.php?sessionid=29756293changeseverytime

So how do I create a contingency to make sure the back navigation works correctly as expected for a variety of web apps and sites (there are lot of variability in terms of how the back button will behave).

like image 243
KJW Avatar asked Nov 15 '11 15:11

KJW


People also ask

How do I navigate back in Selenium?

The respective command that takes you back by one page on the browser's history can be written as: driver. navigate(). back();

What is the proper command to navigate to in Selenium?

navigate().to() We can use either method and it will load a new web page in the current browser window. This method operates exactly like the get() method from Browser's Method category. In fact, get() and to() are processed using an HTTP GET operation.

Which WebDriver method navigates to a URL in the browser?

Selenium WebDriver provides methods to navigate to a url; these are driver. get() and driver. navigate().to() .


1 Answers

Why don't you store the location of the page that you want to verify, hit a link, use the goBack and then verify location of check the variables (the one you stored and the location of the verify page)?

By the way, if your site uses AJAX I suggest you use the pause function that waits for the AJAX lib. To fully load, or set the speed of your site (maybe combine them together in rare cases).

like image 84
Roy Segall Avatar answered Oct 03 '22 07:10

Roy Segall