Forum Discussion

azharuddin's avatar
azharuddin
Occasional Contributor
7 years ago

How to scroll down a web page to verify a specific element?

I'm learning how to use selenium and I'm stuck on figuring out how to scroll down in a website to verify an element exists.

 

I tried using the methods that was found in this question Scrolling to element using webdriver? but selenium won't scroll down the page. Instead it'll give me an error

 

"selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: element"

Heres the codes I am using

 

moveToElement:

element = driver.find_element_by_xpath('xpath')actions = ActionChains(driver)actions.move_to_element(element).perform()

Scrolling into View

element = driver.find_element_by_xpath('xpath')driver.execute_script("arguments[1].scrollIntoView();", element)

The whole code:

from selenium import webdriverfrom selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChainsdriver = webdriver.Firefox()driver.get("https://www.linkedin.com/")element = 
driver.find_element_by_xpath('/html/body/div/main/div/div[1]/div/h1/img')element = driver.find_element_by_xpath('//*[@id="login-email"]')element.send_keys('')element = driver.find_element_by_xpath('//*[@id="login-password"]')element.send_keys('')element = driver.find_element_by_xpath('//*[@id="login-submit"]')element.click();element = driver.find_element_by_xpath('')actions = ActionChains(driver)actions.move_to_element(element).perform()

 

1 Reply

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    This forum is dedicated to TestComplete, test automation tool by SmartBear (https://smartbear.com/) and has nothing with Selenium.

    However, with the web page element been located, you may try to use the .scrollIntoView() native DOM method to make the element visible in the browser viewport.