What will currentUrl contain after execution if clicking the button navigates to page2?
medium
A. "https://example.com/page1"
B. null
C. Throws NoSuchElementException
D. "https://example.com/page2"
Solution
Step 1: Understand navigation flow in code
The driver opens page1, then clicks a button that navigates to page2.
Step 2: Check what getCurrentUrl() returns after navigation
It returns the URL of the current page, which should be page2 after clicking.
Final Answer:
"https://example.com/page2" -> Option D
Quick Check:
After click, URL updates to new page [OK]
Hint: getCurrentUrl() shows current page URL [OK]
Common Mistakes:
Assuming URL stays the same after navigation
Confusing getCurrentUrl() with getPageSource()
Thinking click throws exception without checking element presence
4. Identify the error in this Selenium Java code for multi-page navigation:
driver.get("https://example.com/home");
WebElement link = driver.findElement(By.className("nav-link"));
link.click();
String title = driver.getTitle();
assert title.equals("Home Page");
medium
A. Missing driver.quit() after test
B. Incorrect assertion method syntax
C. Using className locator without checking multiple matches
D. Using getTitle() instead of getCurrentUrl()
Solution
Step 1: Analyze locator usage
Using By.className("nav-link") may find multiple elements, causing ambiguity.
Step 2: Check other code parts
Assertion syntax is correct, driver.quit() is optional, and getTitle() is valid for title check.
Final Answer:
Using className locator without checking multiple matches -> Option C
Quick Check:
className may match many elements [OK]
Hint: Ensure locators uniquely identify elements [OK]
Common Mistakes:
Ignoring that className can match multiple elements
Thinking getTitle() is wrong for title checks
Believing driver.quit() is mandatory in every snippet
5. You want to test a multi-page flow where after login, the user clicks a menu to open a settings page, then clicks a logout button. Which Selenium Java approach correctly verifies the flow?
hard
A. Use driver.get() for login page, findElement().sendKeys() for login, click menu link, verify settings URL, click logout, verify login URL
B. Use driver.navigate().refresh() after each click to ensure page loads
C. Use driver.get() only once at login, then use JavaScript to change URLs for other pages
D. Use driver.findElement(By.tagName("button")).click() for all clicks without verifying page changes
Solution
Step 1: Outline correct multi-page test steps
Start at login page, perform login, navigate via clicks, verify URLs after each step.
Step 2: Evaluate options for best practice
Use driver.get() for login page, findElement().sendKeys() for login, click menu link, verify settings URL, click logout, verify login URL follows proper navigation and verification. Others misuse refresh, JavaScript URL changes, or skip verification.
Final Answer:
Use driver.get() for login page, findElement().sendKeys() for login, click menu link, verify settings URL, click logout, verify login URL -> Option A
Quick Check:
Navigate and verify URLs step-by-step [OK]
Hint: Navigate and verify each page URL after clicks [OK]
Common Mistakes:
Refreshing unnecessarily after clicks
Changing URLs via JavaScript instead of real navigation
Clicking without verifying page changes
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.