J.Doe J.Doe - 14 days ago 9
Python Question

(Python, Selenium WD) Нow to receive and transfer the list to a cycle?

I have this code

lst = ["Appearence","Logotype", "Catalog", "Product Groups", "Option Groups","Manufacturers","Suppliers",
"Delivery Statuses","Sold Out Statuses", "Quantity Units", "CSV Import/Export", "Countries","Currencies","Customers"]

for item in lst:
wd.find_element_by_link_text(item).click()
assert wd.title != None


I not want to write list by hand.
I want to receive the list - lst directly from the browser.
I use

m = wd.find_elements_by_css_selector('li[id=app-]')
print(m[0].text)

Appearence


I don't know how to transfer the list to a cycle

look this picture screen browser

Please help me to understand how to use the list and to transfer it to a cycle

Answer

In your example variable m will be a list of WebElements you can directly click, to iterate over them just use a for loop:

m = wd.get_elements_by_css_selector('li#app-')

for elem in range(1, len(m)+1):
    wd.get_element_by_css_selector('li#app-:nth-child({})'.format(elem)).click()
    assert wd.title is not None