Archiee
Archiee

Reputation: 91

Increment string number within selenium driver url in Python

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 :

(current_url123)

Upvotes: 0

Views: 298

Answers (1)

PDHide
PDHide

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

Related Questions