V
V
vante_scribaxxi2017-08-06 01:15:31
Python
vante_scribaxxi, 2017-08-06 01:15:31

How to find a select element in selenium by the text of one of its options?

In general, there is one page, and select on it. After selecting an element, several more select elements are dynamically drawn. Etc. In the script, the selection options are stored in an array - [select1,select2,select3...], as the value of one of the options of the given select, i.e.:

<select name='par[3345]'>
  <option>Квартира</option>
  <option>Дом</option>
</select>
<select name='par[4212]'>
  <option>Куплю</option>
  <option>Продам</option>
</select>

In the script: The problem is that without static attributes it is very difficult to search for suitable selects, plus after selecting the desired option, more than 1 select can be created, which is solved by a nested array: provided that the search for the desired select' and will be searched for by one of its options (option)! How to solve such a problem in this way?
mas=["Дом","Продам"]
["Дом","Продам",["Кирпичный","2 этажа","200кв.м"]]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2017-08-06
@vante_scribaxxi

selects = driver.find_elements_by_tag_name('select')
need_select = None
condition = 'Кирпичный'
for select in selects:
    options = select.find_elements_by_tag_name('option')
        for opt in options:
            if opt.text == condition:
                need_select = select

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question