Getting data based on multiple values in Selenium

34 views Asked by At

There are multiple options in select. With the code below, I can only retrieve data according to the option. If there is more than one value, example: value='1628', value='1373' value='1441', how can I pull it at the same time?

shr = browser.find_element_by_xpath("/html/body/div\[1\]/div/section\[2\]/div/div/div\[1\]/div\[2\]/form/fieldset/div/div\[2\]/select /option\[@value='1628'\]").click()
shr = browser.find_element_by_xpath("/html/body/div\[1\]/div/section\[2\]/div/div/div\[1\]/div\[2\]/form/fieldset/div/div\[2\]/select /option\[@value='1628','1373','1441'\]").click()

And

shr = browser.find_element_by_xpath("/html/body/div\[1\]/div/section\[2\]/div/div/div\[1\]/div\[2\]/form/fieldset/div/div\[2\]/select /option\[@value='1628'\] And \[@value='1373'\] And \[@value='1441'\]").click()

I tried like this but I was not successful.

1

There are 1 answers

0
Allwin baby On

Don't Specify '@value' property of the option tag if u want all the option from a particular select tag.
give till the '/option' in xpath and u will get all the option elements.

select_option_list = browser.find_elements_by_xpath("/html/body/div\[1\]/div/section\[2\]/div/div/div\[1\]/div\[2\]/form/fieldset/div/div\[2\]/select/option")#to select all the options inside the select
for i in select_option_list:
    print(i.get_attribute("innerHTML")) #to print the values of options