-1

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.

https://www.screencast.com/t/9ZUC3iZbC0

enter image description here

  • 1
    Share what you have tried so far. – Shahid May 3 '18 at 5:35
0

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 ....
0

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')
options.select_by_visible_text('Mango')
# 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 '18 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 '18 at 7:06
0

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

wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//android.widget.ListView[@index='0']/android.widget.TextView[@resource-id='android:id/text1']")));
            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");
                if(driver.findElementByXPath(xpathForOnlineChannel).getText().equalsIgnoreCase(onlineChannels[i])){
                    System.out.println("channels "+driver.findElementByXPath(xpathForOnlineChannel).getText());
                }else{
                    break;
                }

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.