Zum Hauptinhalt springen
Echtzeit-Radar & Feeds
Alle RSS Feeds ➔
👥 Community & Social
Linux Tipps & HardeningRufus clone for Linux(29.09.2026 um 00:49 Uhr)
•
Windows Tipps & SecurityWhat distro should I use blah blah blah(29.09.2026 um 01:57 Uhr)
•
Sichere ProgrammierungJulian Goldie SEO: This Tiny AI Model Makes 28 Decisions a Second(29.09.2026 um 03:00 Uhr)
•
IT Security Toolsphantom-grid(29.09.2026 um 02:40 Uhr)
•
IT Security NachrichtenFBI-Datenleck: ShinyHunters soll PII von Tausenden gestohlen haben(29.09.2026 um 03:30 Uhr)
••
IT Security NachrichtenRSA-Sicherheit schwächer als gedacht:Forscher zeigen neuen Angriff(25.09.2026 um 10:38 Uhr)
•••
IT Security DownloadsGitHub Release: ollama/ollama v0.35.0 (28.09.2026)(28.09.2026 um 22:31 Uhr)
•
Linux Tipps & HardeningRufus clone for Linux(29.09.2026 um 00:49 Uhr)
•
Windows Tipps & SecurityWhat distro should I use blah blah blah(29.09.2026 um 01:57 Uhr)
•
Sichere ProgrammierungJulian Goldie SEO: This Tiny AI Model Makes 28 Decisions a Second(29.09.2026 um 03:00 Uhr)
•
IT Security Toolsphantom-grid(29.09.2026 um 02:40 Uhr)
•
IT Security NachrichtenFBI-Datenleck: ShinyHunters soll PII von Tausenden gestohlen haben(29.09.2026 um 03:30 Uhr)
••
IT Security NachrichtenRSA-Sicherheit schwächer als gedacht:Forscher zeigen neuen Angriff(25.09.2026 um 10:38 Uhr)
•••
IT Security DownloadsGitHub Release: ollama/ollama v0.35.0 (28.09.2026)(28.09.2026 um 22:31 Uhr)
•
Intelligence View
⚡ tsecurity.de Intelligence

🧪 Selenium with Python: A Practical Cheat Sheet for Modern Test Automation

If you’re a QA engineer stepping into automation — or an SDET who just needs a quick refresher — this cheat sheet covers the Selenium + Python essentials you actually use at work. No theory overload. No outdated patterns. Just practical ex…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

If you’re a QA engineer stepping into automation — or an SDET who just needs a quick refresher — this cheat sheet covers the Selenium + Python essentials you actually use at work.



No theory overload. No outdated patterns. Just practical examples you can copy, adapt, and scale.



Thanks for reading! Subscribe for free to receive new posts and support my work.



✅ Setup & Installation



Install Selenium:



pip install selenium



Make sure the correct browser driver is available in your system PATH:



Chrome → chromedriver



Firefox → geckodriver



Edge → msedgedriver



🚀 Starting the Browser



Launch Chrome

from selenium import webdriver



driver = webdriver.Chrome()



driver.get(”https://example.com”)



Headless Mode (Recommended for CI)



from selenium.webdriver.chrome.options import Options



options = Options()



options.add_argument(”--headless”)



options.add_argument(”--window-size=1920,1080”)



driver = webdriver.Chrome(options=options)



🔍 Locating Elements (The Most Important Skill)



Always prioritize reliable, stable locators.



from selenium.webdriver.common.by import By



Preferred Locators

driver.find_element(By.ID, “submit”)



driver.find_element(By.NAME, “email”)



driver.find_element(By.CSS_SELECTOR, “.login-button”)



driver.find_element(By.CSS_SELECTOR, “input[type=’password’]”)



XPath (Use Sparingly)



driver.find_element(By.XPATH, “//button[text()=’Login’]”)



✅ Tip: If your tests break often, your locators are probably the problem.



✍️ User Interactions



element.click()

element.send_keys(”[email protected]”)

element.clear()

Read values:

element.text

element.get_attribute(”value”)



⏳ Waiting for Elements (Non‑Negotiable)



Explicit Waits (Best Practice)

from selenium.webdriver.support.ui import WebDriverWait

from selenium.webdriver.support import expected_conditions as EC

wait = WebDriverWait(driver, 10)

login_btn = wait.until(

EC.element_to_be_clickable((By.ID, “login”))

)



Common conditions:



EC.presence_of_element_located

EC.visibility_of_element_located

EC.element_to_be_clickable



❌ Avoid time.sleep() — it causes flaky tests.



📄 Forms & Dropdowns



from selenium.webdriver.support.ui import Select

dropdown = Select(driver.find_element(By.ID, “country”))

dropdown.select_by_visible_text(”India”)



🔔 Alerts, Frames & Windows



Alerts



alert = driver.switch_to.alert

alert.accept()



iFrames



driver.switch_to.frame(”frameName”)

driver.switch_to.default_content()



Multiple Tabs

driver.switch_to.window(driver.window_handles[1])



📜 Scrolling & JavaScript



driver.execute_script(”window.scrollTo(0, document.body.scrollHeight)”)

driver.execute_script(”arguments[0].scrollIntoView()”, element)



📷 Screenshots (For Failing Tests)



driver.save_screenshot(”failure.png”)

element.screenshot(”button.png”)



🧹 Cleanup

driver.close()

driver.quit()



🚀 Selenium + Pytest: Real‑World Automation Setup

Selenium alone isn’t enough. Pytest makes your automation scalable, readable, and CI‑ready.

**

✅ Install Pytest**



pip install pytest



🧱 Project Structure (Recommended)

tests/

├── pages/

│ └── login_page.py

├── conftest.py

├── test_login.py

└── pytest.ini



🔁 Pytest WebDriver Fixture



conftest.py

import pytest

from selenium import webdriver



@pytest.fixture

def driver():

driver = webdriver.Chrome()

driver.maximize_window()

yield driver

driver.quit()



✅ Automatically manages setup & teardown

✅ Cleaner than setUp() / tearDown()



🧪 Writing a Test



def test_valid_login(driver):

driver.get(”https://example.com/login”)

driver.find_element(By.ID, “username”).send_keys(”admin”)

driver.find_element(By.ID, “password”).send_keys(”password”)

driver.find_element(By.ID, “login”).click()

assert “Dashboard” in driver.title



🧠 Using Page Object Model with Pytest



pages/login_page.py



class LoginPage:

def init(self, driver):

self.driver = driver

def login(self, user, pwd):

self.driver.find_element(By.ID, “username”).send_keys(user)

self.driver.find_element(By.ID, “password”).send_keys(pwd)

self.driver.find_element(By.ID, “login”).click()



test_login.py



def test_login_success(driver):

page = LoginPage(driver)

page.login(”admin”, “password”)

assert “Dashboard” in driver.title



🏷️ Pytest Markers (Power Feature)



@pytest.mark.smoke

def test_smoke_login():

pass



Run specific tests:



pytest -m smoke



📊 HTML Reports (CI‑Friendly)



pip install pytest-html

pytest --html=report.html

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten 🧪 Selenium with Python: A Practical Cheat Sheet for Modern Test Automation

Thematisch verwandte Begriffe: Selenium, with, Python, Practical · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

💬 Kommentare werden geladen…
Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-101916 | @grpc/grpc-js implements the core functionality of gRPC purely in JavaS…
Advisory →
tsecurity.de Icon
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag