Complete the code to open a browser and navigate to a URL.
WebDriver driver = new ChromeDriver(); driver.[1]("https://example.com");
The get method loads a new web page in the current browser window.
Complete the code to find a button by its ID and click it.
WebElement button = driver.findElement(By.[1]("submitBtn")); button.click();
The id locator finds an element by its unique ID attribute.
Fix the error in the code to wait until an element is visible before clicking.
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); wait.until(ExpectedConditions.[1](By.id("loginBtn"))); driver.findElement(By.id("loginBtn")).click();
visibilityOfElementLocated waits until the element is visible on the page.
Fill both blanks to correctly switch to a new browser tab and close it.
String originalHandle = driver.getWindowHandle(); for (String handle : driver.[1]()) { if (!handle.equals(originalHandle)) { driver.[2](handle); driver.close(); } } driver.switchTo().window(originalHandle);
getWindowHandles() returns all open window handles.switchTo().window(handle) switches control to the specified window.
Fill all three blanks to create a test that opens a page, waits for a button, clicks it, and verifies the title.
driver.[1]("https://example.com"); WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); wait.until(ExpectedConditions.[2](By.id("startBtn"))); driver.findElement(By.id("startBtn")).click(); assertEquals("Welcome Page", driver.[3]());
The test opens the URL with get, waits for the button to be visible with visibilityOfElementLocated, and verifies the page title with getTitle.