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

(Python, Selenium WD) How to automate these actions - cycle or function?

How to automate these actions - cycle or function?

wd.find_element_by_link_text("Logotype").click()
assert "Logotype" in wd.title
wd.find_element_by_link_text("Catalog").click()
assert "Catalog" in wd.title
wd.find_element_by_link_text("Product Groups").click()
assert "Product Groups" in wd.title
wd.find_element_by_link_text("Option Groups").click()
assert "Option Groups" in wd.title

Answer

Looks like what you'll do with a for loop. All you need do is put the strings in a list:

lst = ["Logotype", "Catalog", "Product Groups", "Option Groups"]

for item in lst:
    wd.find_element_by_link_text(item).click()
    assert item in wd.title
Comments