SELENIUM : Navigation commands supported by Selenium?

Опубликовано: 18 Апрель 2023
на канале: SDET Automation Testing Interview Pro
167
4

SELENIUM : Navigation commands supported by Selenium?

SDET Automation Testing Interview Questions & Answers

We will be covering a wide range of topics including QA manual testing, automation testing, Selenium, Java, Jenkins, Cucumber, Maven, and various testing frameworks.

SELENIUM : Navigation commands supported by Selenium?

Selenium provides several navigation commands to simulate user interactions with a web page.

Here are some of the commonly used navigation commands in Selenium:

get(String url): This command navigates to the specified URL.

navigate().to(String url): This command is also used to navigate to a URL. The main difference between this command and get() is that navigate().to() can be used to navigate to a different domain as well, while get() can only be used to navigate within the same domain.

navigate().back(): This command navigates back to the previous page in the browser's history.

navigate().forward(): This command navigates forward to the next page in the browser's history.

navigate().refresh(): This command refreshes the current page.

Here's an example of using some of these navigation commands in Selenium:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class SeleniumNavigationExample {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");

// Launch Chrome browser
WebDriver driver = new ChromeDriver();

// Navigate to the URL
driver.get("https://www.example.com");

// Navigate to a different URL
driver.navigate().to("https://www.selenium.dev");

// Navigate back to the previous page
driver.navigate().back();

// Navigate forward to the next page
driver.navigate().forward();

// Refresh the current page
driver.navigate().refresh();

// Close the browser
driver.quit();
}
}