Sudi
Sudi

Reputation: 19

can I scroll a web page using selenium webdriver in python

browser = webdriver.Firefox()

browser.get('http://www.example.com')

search_items = []

for i in range(0, 20):   
    items = browser.find_element_by_xpath(
        '//*[@id="asrt%s"]/section[2]'
        % str(i))
    driver.items("window.scrollTo(0, Y)")

    print items.text

Upvotes: 1

Views: 1596

Answers (2)

TOlson05
TOlson05

Reputation: 41

If you are looking to scroll to a WebElement you can use:

((JavascriptExecutor)driver).executeScript("arguments[0].scrollIntoView(true);", element);

Where element is the variable to a WebElement you have set.

Upvotes: 1

Saurabh Garg
Saurabh Garg

Reputation: 201

you can use

driver.execute_script("window.scrollTo(0, Y)")

Upvotes: 0

Related Questions