Selenium WebDriver Browser Navigation Commands
The navigate interface exposes the ability to move backwards and forwards in your browser’s history but navigate().to() and get() do exactly the same thing. One’s just a lot easier to type than the other.
To Command
Purpose : This command is use to navigate on specific page or URL in between the test Command : driver.navigate().to(URL); Parameters : url – The URL to load. It is best to use a fully qualified URL
|
driver.navigate().to("http://www.gooogle.com");
|
Forward Command
Purpose : This command is use to go on to next page like browser’s forward button.
|
driver.navigate().forward();
|
Back Command
Purpose : This command is use to go back to previous page like browser’s back button.
|
driver.navigate().back();
|
Refresh Command
Purpose : This command is use to refresh the current page.
|
driver.navigate().refresh();
|
Practice Exercise
1) Launch new Browser 2) Open Toolsqa.com website 3) Click on About link ( On top navigation) 4) Come back to Home page (Use ‘Back’ command) 5) Again go back to About page (This time use ‘Forward’ command) 6) Again come back to Home page (This time use ‘To’ command) 7) Refresh the Browser (Use ‘Refresh’ command) 8) Close the Browser
Solution
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
package automationFramework;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class PracticeNavigationCommands {
private static WebDriver driver = null;
public static void main(String[] args) {
// Create a new instance of the Firefox driver
driver = new FirefoxDriver();
// Open ToolsQA website
driver.get("http://www.toolsqa.com");
// Put an Implicit wait on driver
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
// Click on About link
driver.findElement(By.linkText("ABOUT")).click();
// Go back to Home Page
driver.navigate().back();
// Go forward to About page
driver.navigate().forward();
// Go back to Home page
driver.navigate().to("http://www.toolsqa.com");
// Refresh browser
driver.navigate().refresh();
// Close browser
driver.close();
}
}
|
No comments:
Post a Comment