Reputation: 15
I need to:
ACTUAL RESULT: It keeps opening a new browser window, and only goes to the first URL (google.com), then closes it... and re-opens a new window at Google.com. The loop is infinite and doesn't stop after 3 URLs in this example.
EXPECTED/DESIRED RESULT: Loop through the URLs, and then stop the script once done (in this case, opening the browser 3 times, loading 3 different URLs, closing each browser)
Any help would be appreciated.
This is the code I tried
urlstoloop = ["http://google.com",
"http://yahoo.com",
"http://msn.com"]
i = 0
while i < len(urlstoloop):
web = webdriver.Chrome()
web.get(urlstoloop[i])
CUSTOM CODE
web.quit()
i += 1
Upvotes: 0
Views: 179
Reputation: 6912
You are incremenitng i
outside of the loop. This should be done inside the loop, so indent it in:
while i < len(urlstoloop):
#something...
i += 1
Also, as suggested by @Alderven, for this case it's better to use a for loop to iterate over the list of URLs. Just wanted to point out the mistake in your existing code.
Upvotes: 0