About this question
I would like to select an https://www.janbasktraining.com/blog/webelement-in-selenium/webelement</select>
I would like to select an https://www.janbasktraining.com/blog/webelement-in-selenium/webelement</select>
Log in to share your answer and help other learners.
Log in to answerBest Answer · By JanBask Cyber Security Expert
Answered on Oct 18, 2022
I think using selenium.webdriver.support.ui.Select is the cleanest way for selenium select dropdown python:
from selenium import webdriver
from selenium.webdriver.support.ui import Select
b = webdriver.Firefox()
# navigate to the page
select = Select(b.find_element_by_id(....))
print select.options
print [o.text for o in select.options] # these are string-s
select.select_by_visible_text(....)Using this approach is also the fastest way. I wrote fast_multiselect as analogous function to multiselect_set_selections. On a test with 4 calls to multiselect_set_selections on lists of about 20 items each, the average running time is 16.992 seconds, where fast_multiselect is only 10.441 seconds. Also the latter is much less complicated.
from selenium.webdriver.support.ui import Select
def fast_multiselect(driver, element_id, labels):
select = Select(driver.find_element_by_id(element_id))
for label in labels:
select.select_by_visible_text(label)
Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.
Step-by-step Cyber Security guides from industry experts
Common Cyber Security interview questions, answered
Guides, tips and career advice on Cyber Security from JanBask experts.
Cyber Security Ethical Hacker Roles and Responsibilities: What Do Ethical Hackers Actually Do?
What does an ethical hacker actually do? See the five-phase process, daily tasks, required skills, and where ethical hackers work.
Cyber Security Penetration Tester Roles and Responsibilities: What Does a Pen Tester Do?
Learn what a penetration tester does, including key roles, responsibilities, daily tasks, tools, skills, reporting, and…
Cyber Security GRC Analyst Roles and Responsibilities: What Does a GRC Analyst Do?
What does a GRC analyst actually do? See the core responsibilities, how they grow by experience level, a daily routine, tools,…
Cyber Security SOC Analyst Roles and Responsibilities: What Does a SOC Analyst Do?
What does a SOC analyst actually do? Explore core responsibilities, the Tier 1–3 structure, daily tasks, tools, and skills in…