How to Stop a For-Loop at a special number using Python

0 votes

I want to for loop at specific point.

I know the method range() but this doesn´t help me because I am iterating in a list. Either it doesnt Work with range() or I just dont know.Globally I save this Variable.:

productAmount = 4

Below is the method:

def amazonChecker(keyword):

driver = webdriver.Chrome('./driver/chromedriver.exe')

driver.get(url)

titels = driver.find_elements_by_tag_name('h2')

for titel in titels:

    counter =+ 1

    if counter < productAmount:

        print(titel.text)

sleep(5)

driver.close
May 25, 2018 in Selenium by Martin
• 4,320 points
448 views

1 answer to this question.

0 votes

driver.find_elements_by_tag_name() returns a list of WebElements.

You can use options like list slicing to make a copy of this list containing only the subset of items you specify.

answered May 25, 2018 by Samarpit
• 5,910 points

Related Questions In Selenium

0 votes
1 answer

How to upload a resume to a website using selenium in python?

Use this code, this will help you: from ...READ MORE

answered Apr 20, 2018 in Selenium by Vardy
• 2,360 points
2,588 views
0 votes
1 answer

How to I switch to a new window for links with “blank” targets using Capybara?

Capybara 2.3 includes the new window management ...READ MORE

answered Jul 11, 2018 in Selenium by Meci Matt
• 9,460 points
3,425 views
0 votes
1 answer

How to click a span with given text using Selenium Python

If ALL_USA is subject to change, then ...READ MORE

answered Jul 26, 2018 in Selenium by Samarpit
• 5,910 points
6,907 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
12,711 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
8,608 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
6,680 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,551 views
+1 vote
1 answer
0 votes
1 answer

How to login a forum using Selenium with Python

You should try to directly log in ...READ MORE

answered Apr 27, 2018 in Selenium by Samarpit
• 5,910 points
2,378 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP