Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dropdown interact
#1
Basically this for loop is supposed to work if a dropdown menu is shown on the page. I could've made it work just for one item of the list, but could not make it loop over all the dropdown items.

How could I make It work for all the dropdown items?


           # IF THE DROPDOWN IS SHOWED FOR THIS CLIENT
            if self.driver.find_element_by_xpath('/html/body/main[1]/nav/ul/li[1]/span').is_displayed():
                qntbenef = 'SIM'
                print('Mais de um beneficio')

                # DROPDOWN CLICK TO MAKE ITEMS LIST VISIBLE
                self.driver.find_element_by_xpath('/html/body/main[1]/nav/ul/li[1]/span').click()

                # DROPDOWN LIST = DROPD
                dropd = self.driver.find_elements_by_xpath('/html/body/main[1]/nav/ul/li[1]/ul')

                # PRINT THE ITEMS OF THE DROPDOWN
                for item in dropd:
                    print(item.text)

                    item.click()

                    nome = self.driver.find_element_by_xpath(
                        "/html/body/main[1]/div[@id='dashboard'][not(contains(@class, 'left hide'))]"
                        "/div[1]/div[1]/div[1]/h2").text

                    print(nome)
The code works fine till print(item.text) and prints all the items of the dropdown menu, but them the code interacts just with the first item of the menu...

Here's the full code: https://github.com/moisesfelipee/web-scr...aster/1.py
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Generating dynamic dropdown list test 1 1,428 Aug-30-2023, 08:00 AM
Last Post: blessinguvula
  Python Selenium (Dropdown-) data Robin_at_Cantelli 2 6,158 Dec-29-2021, 03:16 AM
Last Post: ondreweil
  Selenium Python for Dropdown not working gj31980 1 2,612 Oct-27-2020, 02:02 AM
Last Post: gj31980
  Python to interact with the Linux Command Line - Centos/RHEL redhat_boy 2 2,160 May-10-2020, 08:33 AM
Last Post: redhat_boy
  While loop skips multiple dropdown menu options and then works as intended newbie_programmer 1 2,842 Dec-23-2019, 10:26 PM
Last Post: keuninkske
  How can i scrape dropdown value ? caca 0 2,945 Nov-03-2019, 11:24 PM
Last Post: caca
  Python Flask Dependent Dropdown Anfaa 3 18,368 Oct-24-2018, 09:35 PM
Last Post: nilamo
  Click dropdown menu option with Selenium PyChrome AcszE 3 5,870 Oct-26-2017, 10:07 PM
Last Post: metulburr
  Create Dictionary List (From a webpage dropdown) for Comparison to a CSV File Guttmann 5 5,852 Mar-31-2017, 01:29 AM
Last Post: Guttmann

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020