Python Selenium - how to calculate the number of options in select in the form and list all options?

Python Selenium - how to calculate the number of options in select in the form and list all options?

Hi,

could anyone advise me how to find a tool for automatic testing of web applications Python Selenium html element input? Specifically, my point is to get all the options from the select with id id = FiltrSoutez and list all the values that are there. Please help. Thanks

REPLY


Hi,

so i solved it, these are my notes to count the number of option in select and list all option:

# several total options in form select

selectId = 'FiltrSoutez'
selectBoxx = driver.find_element_by_id(selectId)
countOptions = len(selectBoxx.find_elements_by_tag_name('option'))
print(countOptions)

selectBox = Select(driver.find_element_by_id(selectId))
print (selectBox.options)
print ([o.text for o in selectBox.options])



# read from form select option values and print

def loopSelectSoutezClick():
selectId = 'FiltrSoutez'

#how many options
selectBoxx = driver.find_element_by_id(selectId)
countOptions = len(selectBoxx.find_elements_by_tag_name('option'))
print(countOptions)

options = [x for x in selectBoxx.find_elements_by_tag_name("option")]
for element in options:
print (element.get_attribute("value"))


OLD VARIANT:
#how to calculate the number of options in the select box id = FiltrSoutez

# loop for clicking on all options in the select
def loopSelectSoutez():
selectId = 'FiltrSoutez'


selectBox = driver.find_element_by_id(selectId)

# how many options are there in the form select
countOptions = len(selectBox.find_elements_by_tag_name('option'))

print(countOptions)

Související obsah

linux

python

selenium

web

webscraping

Komentáře

Vaše reakce na Python Selenium - jak ve form spočítat počet option v select a vypsat všechny option?

Reference

Podívejte se na naše reference

Prohlédnout

Aplikace

Podívejte se na naše aplikace

Prohlédnout

Co umíme?

Podívejte se co umíme

Prohlédnout

Co umíme?

Vytváříme sofistikované aplikace pro náročné

Od webových aplikací přes android až po převodové můstky či složité informační systémy.

Podívejte se k nám

Máte ještě čas? Podívejte se na další rubriky

Tento web používá soubory cookie. Dalším procházením tohoto webu vyjadřujete souhlas s jejich používáním.. Více informací zde.