Introduction
Browser control lets us automate and test websites just like a real user would. It is the base for all web testing.
Browser control lets us automate and test websites just like a real user would. It is the base for all web testing.
from selenium import webdriver # Create a browser driver driver = webdriver.Chrome() # Open a website driver.get('https://example.com') # Close the browser driver.quit()
Use webdriver.Chrome() to control the Chrome browser.
driver.get() opens the website URL you want to test.
driver = webdriver.Firefox()
driver.get('https://example.com')driver = webdriver.Chrome()
print(driver.title)
driver.quit()This script opens a browser, goes to example.com, prints the page title, and closes the browser.
from selenium import webdriver # Start Chrome browser driver = webdriver.Chrome() # Open example.com driver.get('https://example.com') # Print the page title print(driver.title) # Close the browser driver.quit()
Always close the browser with driver.quit() to free resources.
Browser control mimics real user actions, so tests are more reliable.
Browser control is the base for automating web tests.
It helps test websites like a real user would.
Using browser control saves time and finds bugs early.
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.get('https://example.com')
element = driver.find_element(By.TAG_NAME, 'h1')
print(element.text)
driver.quit()from selenium import webdriver
driver = webdriver.Chrome
driver.get('https://example.com')Pass the test and this pattern moves unknown