May-04-2020, 01:11 AM
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?
Here's the full code: https://github.com/moisesfelipee/web-scr...aster/1.py
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
