Search code examples
c#seleniumautomation

How to scroll down properly in selenium C#


I have used actions class to scroll down but when it scrolls down click code is not working:

  driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
        
  Actions actions = new Actions(driver);
  actions.SendKeys(Keys.PageDown).Build().Perform();
       
       
 driver.FindElement("//a[@href='http://automationpractice.com/index.php? 
 controller=order&step=1']").Click();
        
 //var ele = driver.FindElement(proceed);
 //actions.MoveToElement(ele).Click().Perform();

enter image description here
Please use below id pass to login:

ID : paul@xmail.com

Password : Pass123##


Solution

  • Instead of scrolling approsimatively with PageDown, you should perform scrolling to element in a precise way. Let me know if it works for you

    var element = driver.FindElement("//a[@href='http://automationpractice.com/index.php?controller=order&step=1']");
    actions.MoveToElement(element);
    actions.Perform();
    element.Click();