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
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
# read from form select option values and print
OLD VARIANT:
#how to calculate the number of options in the select box id = FiltrSoutez
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)