Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Current »

Location Strategies

  • Choosing a Location Strategy

Navigate Back And Forward On The Browser

Navigating the history of browser can be easily done using below two methods. The names are self explanatory.

//Go back to the last visited page

driver.navigate().back();

//go forward to the next page

driver.navigate().forward();

Refresh Page

This may be required often. Just a simple refresh of the page equivalent to a browser refresh.

driver.navigate().refresh();

Handling Files

Upload Image to Page

An approach to upload an image to a page is to copy the location of the file to the clipboard, entering it into the search bar and pressing enter.

StringSelection stringSelection = new StringSelection(documentLocation);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(stringSelection, stringSelection);


WebDriver Wait

Different Types of Wait 

  • Implicit Wait - Instructs the web driver to wait for some time by poll the DOM. Once declared, implicit wait will be available for the entire life of web driver instance.
  • Explicit Wait - With the use of ExpectedConditions, explicit wait is custom and can be adjusted. It will be used in the case that the tester wants the execution to wait for some time until some condition is achieved. Explicit waits is code you define to wait for a certain condition to occur before proceeding further in the code.


Note: Implicit Wait and Explicit wait will maximize wait for element for the time duration specified, If they find the element before the next step will be executed. If you want your test to wait for exact time duration, a better approach would be to implement Thread.sleep.

Thread.sleep - In sleep code it will always wait the mentioned seconds, even in case the page is ready to interact after 1 sec.

try{
  Thread.sleep(1000); //1 second
}catch(InterruptedException e){
	e.printStackTrace();
}




  • No labels