Skip to content
Advertisement

Only click on first 10 items in Selenium element list

I want to click on the first 10 elements from the returned list below.

Currently, Selenium is clicking on all the elements but I want it to be limited to the first 10 clicks only.

How do I do this?

items1 = driver.find_elements_by_xpath("//div[@class='teams']") 
for items in items1:
    items.click()

Advertisement

Answer

items1 = driver.find_elements_by_xpath("//div[@class='teams']")
for items in items1[:9]:
    items.click()
Advertisement