J.Doe J.Doe - 1 year ago 119
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:
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-]')


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 Source

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):
    assert wd.title is not None
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download