Reputation: 91
I am Writing a Script for automation purposes. The Selenium driver wont update the page number, so the driver can proceed to the next page number.
sample.py
number_to_loop_over = 5
page = number_to_loop_over
while True:
if page != 0:
#page must be string so driver can be executed
driver.get(driver.current_url +str(page))
page = page - 1
if page == 0:
break
Problem :
str(page)
, is not been replaced once the current_url
is called; instead this is what's happening :(current_url123)
current_url
is called for the first time, 1
gets inserted, but if called again, str(page)
gets appended beside the previous number.Upvotes: 0
Views: 298
Reputation: 19979
You are calling current url eachtime :
which will be baseurl for first iteration , but second iteration current url will be baseurl+id , and for third it will be baseurl+id+id
so instead of appending id to driver.currenturl , create a variable called baseurl and sotre the initial base url into it.
number_to_loop_over = 5
page = number_to_loop_over
baseUrl = driver.current_url
while True:
if page != 0:
#page must be string so driver can be executed
driver.get( baseUrl +str(page))
page = page - 1
if page == 0:
break
Upvotes: 1