Consider the following Selenium WebDriver code snippet. What will be the URL loaded in the browser after execution?
WebDriver driver = new ChromeDriver(); driver.get("https://example.com"); driver.get("https://openai.com"); String currentUrl = driver.getCurrentUrl(); System.out.println(currentUrl);
Think about what happens when driver.get() is called multiple times.
The driver.get() method loads the given URL in the browser. Calling it twice loads the second URL last, so driver.getCurrentUrl() returns the last loaded URL.
You want to verify that after opening https://example.com, the browser URL is correct. Which assertion is valid in Java with JUnit?
WebDriver driver = new ChromeDriver();
driver.get("https://example.com");Remember to use assertEquals for string equality in JUnit.
In Java, string equality should be checked with assertEquals or .equals(), not with ==. Option C correctly asserts the URL.
After opening a URL with driver.get(), you want to verify the page title. Which Selenium method is best to locate the title?
Page title is not a DOM element you locate with findElement.
The page title is accessed directly by driver.getTitle(). The title tag is not accessible as a normal element for text retrieval.
Examine the code below. It throws a TimeoutException. What is the likely cause?
WebDriver driver = new ChromeDriver(); driver.get("https://example.com"); WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5)); wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("nonexistent")));
Think about what ExpectedConditions.visibilityOfElementLocated waits for.
The wait tries to find an element with id 'nonexistent' which does not exist on the page, causing a timeout.
Choose the best practice for opening URLs in Selenium tests to avoid flaky tests and improve maintainability.
Think about maintainability and flexibility in test automation.
Storing URLs in configuration or environment variables allows easy updates and better test management. Hardcoding URLs in tests reduces flexibility.