🌐 Selenium Browser Operations in Python
Browser operations are the basic commands used to control the browser using Selenium. These operations are the foundation of every Selenium automation script.
🚀 Launch Browser
To start automation, we must first launch a browser using WebDriver.
from selenium import webdriver driver = webdriver.Chrome()
- Firefox →
webdriver.Firefox() - Edge →
webdriver.Edge()
🌍 Open URL
Use get() method to open a website.
driver.get("https://www.google.com")
---
🖥 Maximize Window
Maximizing the browser ensures all elements are visible properly.
driver.maximize_window()---
🔄 Refresh Page
Refresh reloads the current web page.
driver.refresh()---
↩ Navigate Back & Forward
Selenium provides navigation commands to move between pages.
driver.back() driver.forward()---
❌ Close vs Quit Browser
| close() | quit() |
|---|---|
| Closes current browser window | Closes all browser windows |
| Session may remain active | Ends WebDriver session completely |
| Used for single window | Used for complete cleanup |
driver.close() # closes current window driver.quit() # closes all windows and ends session---
- Always maximize window at start
- Always use quit() at end of execution
- Handle browser navigation carefully
- Use waits before navigation
Browser operations are the first step in Selenium automation. Understanding these commands is essential before moving to element interaction, waits, and advanced automation.
No comments:
Post a Comment