I want to select an apple and then after "save and Go" then after it should select an orange like the way it should iterate till coconut, at end of the list it should be select 'Save & Hold'.

I want to know how this can be iterate and loop automatically in python

Here is the screenshot link of the HTML code snippet.


enter image description here

  • 1
    Share what you have tried so far.
    – Shahid
    May 3, 2018 at 5:35

3 Answers 3


Firstly, you have to find the select element:

select_element = driver.find_element_by_id('completed_activity...')

Secondly, you have to find all the options inside this select:

options = select_element.find_elements_by_tag_name('option')

Now you can loop on this list:

for option in options:
    .... your code for each option ....

As mentioned, since you have a select element you first have to find it, then you can either iterate over the list OR you can find a specific option you want to select.

from selenium.webdriver.support.select import Select

options = Select(self.driver.find_element_by_id('completed_activity_screencall_disposition')
# Code here to find and click on Save and Go Button
  • I tried the below but it doesn't work select=Select(driver.find_element_by_id("completed_activity_screencall_disposition")) options = select.options for index in range(0, len(options)): select.select_by_index(index)
    – Anton
    May 3, 2018 at 18:14
  • What kind of error are you getting? I tried your code and it works for me on a separate website.
    – Jonnyboy
    May 4, 2018 at 7:06

Here I am just giving an idea how to select different element from dropdown.You can just add steps you want to do.

            String [] onlineChannels = {"Foodpanda","Swiggy","Zomato"};//replace the text with the items in the dropdown
            for(int i=0;i<3;i++){
                String xpathForOnlineChannel = "//android.widget.TextView[@index="+i+"]";
                Assert.assertTrue(driver.findElementByXPath(xpathForOnlineChannel).getText().equalsIgnoreCase(onlineChannels[i]), "onine channel options are wrong");
                    System.out.println("channels "+driver.findElementByXPath(xpathForOnlineChannel).getText());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.