Introduction
We open URLs in tests to visit web pages and check if they work correctly.
We open URLs in tests to visit web pages and check if they work correctly.
driver.get("https://example.com");driver.get("https://www.google.com");driver.get("https://example.com/login");driver.get("https://mywebsite.com/dashboard");This test opens https://www.example.com, checks if the page title contains 'Example', prints the result, and closes the browser.
import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class OpenUrlTest { public static void main(String[] args) { // Set path to chromedriver executable if needed // System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver"); WebDriver driver = new ChromeDriver(); // Open the URL driver.get("https://www.example.com"); // Check page title contains 'Example' String title = driver.getTitle(); if (title.contains("Example")) { System.out.println("Test Passed: Page loaded with title: " + title); } else { System.out.println("Test Failed: Unexpected page title: " + title); } // Close the browser driver.quit(); } }
Make sure the browser driver (like chromedriver) is installed and its path is set correctly.
driver.get() waits for the page to load before moving on, so you don't need extra waits for page load.
Always close the browser with driver.quit() to free resources.
Use driver.get() to open a web page in your test.
It waits until the page fully loads before continuing.
Check page content or title after opening to verify the page loaded correctly.
driver.get() method do in Selenium WebDriver?driver.get()driver.get()driver.get(String url).driver.get("https://example.com"); is valid Selenium syntax.WebDriver driver = new ChromeDriver();
driver.get("https://example.com");
String title = driver.getTitle();
System.out.println(title);WebDriver driver = new ChromeDriver();
driver.get("https://example.com")
System.out.println(driver.getTitle());driver.get("https://example.com") is missing a semicolon at the end.contains("Example") checks if the title includes the word anywhere.Pass the test and this pattern moves unknown