4

I want to scroll down the page with selenium and python in an loop.

browser.execute_script("window.scrollTo(0, 40)")

^ this works so far.

but how can I reference a variable which will increase with every iteration?

e.g.

def scroll():
    global xx
    xx = 10
    while True:
         browser.execute_script("window.scrollTo(0, xx)")
         xx += 10`

I can see the problem.. the input (window.scrollTo(0, xx)) is a string.

but I dont know how to fix it. Do I need to change the executed script?

1 Answer 1

5

Simply use one of the string interpolation options, for example:

def scroll():
    xx = 10
    while True:
        browser.execute_script("window.scrollTo(0, {})".format(xx))
        xx += 10
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.