Imagine you want to test a website automatically. Why is controlling the browser directly important?
Think about how a user uses a browser to interact with a website.
Browser control lets automated tests simulate real user actions like clicking and typing, which helps find real issues.
Consider this code controlling a browser to open a page and get its title. What will it print?
from selenium import webdriver from selenium.webdriver.chrome.service import Service from selenium.webdriver.chrome.options import Options options = Options() options.add_argument('--headless') service = Service() driver = webdriver.Chrome(service=service, options=options) driver.get('https://example.com') print(driver.title) driver.quit()
What is the title of the page at https://example.com?
The page at https://example.com has the title 'Example Domain', so the code prints that.
You want to click the 'Submit' button on a page. Which locator is the most reliable for browser control?
Consider which locator uniquely identifies the button by its visible text.
Using XPath to find the button by its exact text 'Submit' is precise and less likely to break if other buttons exist.
After navigating to a page, you want to check the title is 'Welcome'. Which assertion is correct?
driver.get('https://example.com/welcome')
page_title = driver.titleThink about how to check if the title exactly matches 'Welcome'.
The assertion checks that the page title equals 'Welcome', confirming correct navigation.
Review this code snippet. It tries to click a button but fails with NoSuchElementException. Why?
from selenium import webdriver from selenium.webdriver.common.by import By with webdriver.Chrome() as driver: driver.get('https://example.com') button = driver.find_element(By.ID, 'submit') button.click()
Think about elements inside frames and how Selenium accesses them.
If the button is inside an iframe, Selenium must switch to that iframe before interacting with elements inside it.