In the previous article we might have learned 3 most use full methods of selenium, now we are going to learn some more of those methods which we will be using on our upcoming articles.
The following are the methods we will seeing in this articles,
1. navigate().back()
This method request to move webpage to previous page.
2. navigate().forward()
This method request to move webpage from next page.
3. close();
Closes the browser application which was opened by selenium.
4. quit();
Closes all the browser application which was opened by selenium.
Code
import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class Methods_of_selenium_02 { public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "D:\\Software\\Selenium\\chromedriver_win32\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.get("https://google.co.in"); driver.get("https://bing.com"); driver.navigate().back(); driver.navigate().forward(); driver.close(); driver.quit(); } }
Explanation
The 1st driver.get() will open google in chrome, then the next driver.get() will open bing. As we have visited the bing after the google, on the compiling the back() the browser will load google them on compiling the forward() it will move from google to bing again.