1

I have a SAP Application and there is dialog box as shown below:**enter image description here**

the html source code of this respective dialog box is enter image description here

As we can see that there is only 18 row when I scroll the bar (show with blue arrow in pic 1) html source code shows another 18 rows since only the 18 row can fit in the dialog box. Now I want to scroll the bar into last and select the last row of the box. How can I do this??

I tried using

public void waitForElement()
        {
            //IJavaScriptExecutor je = (IJavaScriptExecutor)StaticDriver.driver;
            //IWebElement element = StaticDriver.driver.FindElement(By.XPath("(//*[@class= 'slick-cell l0 r0 row_62 cid_col_0']//div)//following-sibling::div"));
            //je.ExecuteScript("arguments[0].scrollIntoView(true);", element);

            var element = StaticDriver.driver.FindElement(By.XPath("(//*[@class= 'slick-cell l0 r0 row_62 cid_col_0']//div)//following-sibling::div"));
            Actions actions = new Actions(StaticDriver.driver);
            actions.MoveToElement(element);
            actions.Perform();
        }

// that xpath is the element of last row.

but i got error Element count be found

How Can I Scroll to the last and find the element?

The View and html source code for last element is:

enter image description here

HTML SOURCE CODE: enter image description here

Biraz Dahal
  • 361
  • 1
  • 5
  • 20
  • For scrolling have a look [here](https://stackoverflow.com/questions/12293158/page-scroll-up-or-down-in-selenium-webdriver-selenium-2-using-java), it is a python example, but I am pretty shore there is a c# pendant. And If you still can't access the item, then have a look if your side uses `iframe` elements, than you ne to [switch the context](https://stackoverflow.com/questions/9942928/how-to-handle-iframe-in-selenium-webdriver-using-java). – Max Apr 22 '20 at 11:14

2 Answers2

2

Try with JavaScript Executor to scroll till end of page :

 js.executeScript("window.scrollTo(0, document.body.scrollHeight)");
mkhurmi
  • 786
  • 4
  • 12
  • No it didn't respond.The bar is not scrolled – Biraz Dahal Apr 23 '20 at 03:10
  • If this comment was for someone else you need to add @other-person’s name, so that he would recieve it. Write now its under my answer so i m the only one who got notification for your comment. – mkhurmi Apr 23 '20 at 14:21
2

The above answer should work, in case you want to scroll till the element you can use the following :-

IWebElement element = driver.FindElement(by);
((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].scrollIntoView(true);", element);
Kumar Rishabh
  • 292
  • 1
  • 9