A. Calling close() before quit() is redundant but safe
B. close() should be replaced with quit() only
C. Calling quit() after close() causes an error
D. The code will open two browser windows
Solution
Step 1: Understand the effect of close() and quit()
close() closes the current window; quit() closes all windows and ends the session.
Step 2: Analyze calling close() before quit()
Calling close() first closes one window, then quit() closes any remaining windows and ends the session. This is redundant but does not cause errors.
Final Answer:
Calling close() before quit() is redundant but safe -> Option A
Quick Check:
close() then quit() is safe but redundant [OK]
Hint: quit() alone suffices; close() before quit() is safe but extra [OK]
Common Mistakes:
Thinking quit() after close() causes error
Believing close() replaces quit()
Expecting multiple windows opened
5. You want to write a Selenium test that opens two tabs, performs actions on both, then closes only the second tab while keeping the first tab open. Which method should you use to close the second tab without ending the WebDriver session?
hard
A. driver.stop()
B. driver.quit()
C. driver.close()
D. driver.exit()
Solution
Step 1: Understand the requirement to close only one tab
To close only the second tab and keep the first open, you must close the current window or tab without ending the session.
Step 2: Choose the correct method
close() closes the current window or tab only, while quit() closes all windows and ends the session. Methods stop() and exit() do not exist in Selenium.
Final Answer:
driver.close() -> Option C
Quick Check:
Use close() to close one tab, quit() closes all [OK]
Hint: Use close() to close one tab, quit() closes all tabs [OK]
Common Mistakes:
Using quit() which closes all tabs
Using non-existent methods like stop() or exit()
Confusing close() with quit()
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.