K
K
ksvdon2015-12-20 21:48:59
linux
ksvdon, 2015-12-20 21:48:59

How to extract text from drop down list and from open page?

There is a dropdown list with a certain number of options:

<option>1.0</option>
<option>2.0</option>

etc...
I also open a page where there will be a certain text and a number (just the number of the selected element of the drop-down list / options, etc. text). I loop through these options and open the pages. I select the elements, click on them, etc., but I would like to extract the text with which the element of the drop-down list is signed (to put it into a variable and compare with what will be later on the page), and I also need to extract the text from the open page. I want to prescribe a certain template so that I can again drive the text that satisfies this template into a variable and work it out.
I'm interested in:
1. How to extract the name of the drop down list item?
(At the moment I'm selecting an element by xpath and iterating through all the dropdown options:
el = browser.find_element_by_xpath('')
opt = el.find_elements_by_tag_name("option")
for option in opt:
     option.click()

)
but I would drive the very name of the element into a variable in the same cycle.
2. How to implement text search by template in an open page?
How to get the text from the page? This is no longer working with elements (buttons, text entry fields, etc.). I don't understand how to implement it.
I write in Python + Selenium.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
southsoutheast, 2015-12-21
@ksvdon

one.

for option in opt:
     option.click()
     print option.get_attribute("value")  #значение элемента
     print option.text #текст элемента

2. Try browser.source. Or look in xpaths.

A
Alexey Varfolomeev, 2015-01-02
@jellyfish

opt = browser.find_element_by_xpath('//option[text()="2.0"]')
opt.click()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question