A
A
Asya2019-11-13 17:29:46
Python
Asya, 2019-11-13 17:29:46

How to select an option from a drop down menu with Selenium (Python)?

How to click on "Two" using python selenium?

<select class="my-class">
            <option>One</option>
            <option>Two</option>
</select>

I tried via xpath, via class and by tag, but nothing helped

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Araya, 2019-11-13
@Araya

First, click on select, then on XPATH select the desired option
. When you try, what does selenium swear at?

1
1001001, 2019-11-13
@1001001

There is a special class https://selenium-python.readthedocs.io/api.html#mo...

from selenium import webdriver
from selenium.webdriver.support.ui import Select

select = Select(driver.find_element_by_class_name('my-class'))

select.select_by_visible_text('Two')

But as an option, you can always click first on the select itself (open it), and then select the value

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question