0

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)

  • once the current_url is called for the first time, 1 gets inserted, but if called again, str(page) gets appended beside the previous number.
0

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.