top of page
back.jpg

Dropdown Automation Selenium Python

How to manage Selenium dropdowns without utilizing the Select class?

# Import the 'time' module for sleep functionality
import time

# Import necessary Selenium libraries
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By

# Create a Service object for the Chrome browser
service_obj = Service()

# Initialize the Chrome WebDriver with the created Service
driver = webdriver.Chrome(service=service_obj)

# Open the specified website
driver.get("https://the-internet.herokuapp.com/")

# Maximize the browser window
driver.maximize_window()

# Set an implicit wait of 3 seconds to allow elements to be found
driver.implicitly_wait(3)

# Click on the 'Dropdown' link using XPath
driver.find_element(By.XPATH, "//a[normalize-space()='Dropdown']").click()

# Select 'Option 2' from the dropdown using its ID
driver.find_element(By.XPATH, "//select[@id='dropdown']").send_keys("Option 2")

# Pause the script execution for 5 seconds using time.sleep
time.sleep(5)

3 views0 comments

Recent Posts

See All

Test case for Valid Coupon Code

This test case checks whether a valid coupon code is successfully applied to a booking cart, the total is updated accordingly, and a success message is displayed. package com.seleniumExamples2024; pu

Keyboard shortcut keys for various operations

General Shortcuts: Ctrl + C: Copy Ctrl + X: Cut Ctrl + V: Paste Ctrl + Z: Undo Ctrl + Y: Redo Ctrl + A: Select All Ctrl + S: Save Ctrl + P: Print Ctrl + F: Find Windows Shortcuts: Windows Key: Open or

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
bottom of page