Identify Scroll bar
Thanks Virendra for sharing the answer!!
Scroll Bar is getting handle by using offset method but still its getting an error i.e.
Exception in thread “main” org.openqa.selenium.interactions.MoveTargetOutOfBoundsException: Offset within element cannot be scrolled into view: (0, 42.5): [object XrayWrapper [object HTMLDivElement]]
Command duration or timeout: 10 milliseconds
&
few time it successfully gets executed
Could you provide the solution for it ?
Hi Ravi,
Please share some code for that you have written on this?
It seems that you are asking the scroll bar to move beyond the capacity of the browser view.
Virender
Hi Virendra,
Following is the script using in the Framework :
WebElement draggablePartOfScrollbar =Â wd.findElement(By.xpath(“//div[@class=’fx-scrollbar-handle’]”));
System.out.println(“identified Scroll Bar”);
System.out.println(draggablePartOfScrollbar1.getLocation().getX());
int x = draggablePartOfScrollbar1.getLocation().getX();
System.out.println(draggablePartOfScrollbar1.getLocation().getY());
int y = draggablePartOfScrollbar1.getLocation().getY();
dragger.moveToElement(draggablePartOfScrollbar).clickAndHold(draggablePartOfScrollbar1).moveByOffset(0, y+260).release().perform();
//dragger.moveToElement(draggablePartOfScrollbar).clickAndHold(draggablePartOfScrollbar1).moveByOffset(y, y+260).release().perform();
Requirements :
This is a Vertical Scroll Bar when we move to mouse pointer to its division it gets displayed and we need to identify it and scroll it down
.
If there is an alternative solution to perform this operation, Please let me know.
Let me give a quick answer without code and will update thread with some code if required
1. So may want to use movetoelement command first to put mouse focus on the element, so that it appears.
2. Then it seems that the y axis that you are using is to big to move the element. This’ might throw the exception mentioned above.
Try smaller values of y
Virender
It would be really helpful if you can share the site which has this scroll element. It seems that its not the browser scroller. Its some scroller on the HTML.
That`s correct Virender,
Its not browser scroller. The website has vertical menu list and the scroll bar is hidden when the mouse moves to the vertical menu the scroll bar gets showed and we need to catch and scroll it down.
that is Microsoft Azure Platform i need to pass the credentials to perform this action so could you come over team viewer when you feel free to come.
Yes Ravi can do this, drop me an email at virender@toolsqa.com and we can take a look.
Also a screenshot and an html of the control will help too.
Virender
Hi Ravi,
There is one more better way to scroll a list or any specific element on screen.
using  >>> org.openqa.selenium.internal.Locatable and
>>>Â org.openqa.selenium.interactions.internal.Coordinates
Try below code
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.interactions.internal.Coordinates; import org.openqa.selenium.internal.Locatable; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; import org.testng.annotations.Test; @Test public class ajaxListScroll { @Test public void ajaxListScrollTest() throws InterruptedException{ // Instantiate driver with browser instance driver.get("http://www.obout.com/ListBox/aspnet_ondemand_virtual_scroll.aspx"); WebDriverWait wait = new WebDriverWait(driver, 70); wait.until(ExpectedConditions.elementToBeClickable(By.id("ctl00_pageContent_PaperBox1_ListBox1_ob_CboListBox1MainContainer"))); String findScroll = driver.findElement(By.xpath("//div[2][@class='ob_iLboICFCM']/div/span")).getText(); //System.out.println("BFP noOfScroll :: " + findScroll); String array[] = findScroll.split(" "); //for (int i=0;i<array.length;i++){ // System.out.println("findScroll split :: " + i + " " + array[i]); //} array[5] = array[5].replace(".",""); int totalElementtoScroll = Integer.parseInt(array[5]); //System.out.println("totalElementtoScroll :: " + totalElementtoScroll); String array2[] = null; int noOFElementonPageLoad=0; for (int i=0;i<array.length;i++){ if (array[i].contains("-")) array2 = array[i].split("-"); } noOFElementonPageLoad = Integer.parseInt(array2[1]); //System.out.println("noOFElementonPageLoad :: " + noOFElementonPageLoad); int noOfTimetoScroll = totalElementtoScroll/noOFElementonPageLoad; //System.out.println("noOfTimetoScroll :: " + noOfTimetoScroll); for (int j=0; j<noOfTimetoScroll; j++){ String xpath = "//ul[@class='ob_iLboICBC']/li[" + noOFElementonPageLoad + "]/b"; //System.out.println("xpath passed :: " + xpath); wait.until(ExpectedConditions.elementToBeClickable(By.xpath(xpath))); WebElement oggy = driver.findElement(By.xpath(xpath)); //System.out.println("oggy.getText() :: " + oggy.getText()); noOFElementonPageLoad += 25; //System.out.println("noOFElementonPageLoad*2 :: " + noOFElementonPageLoad); Thread.sleep(5000); Coordinates coordinate = ((Locatable)oggy).getCoordinates(); coordinate.inViewPort(); } System.out.println("Total Countries " + " :" + totalElementtoScroll); for(int k=1;k<totalElementtoScroll+1;k++){ String printXpath = "//ul[@class='ob_iLboICBC']/li[" + k + "]/b"; //System.out.println("printXpath"+ printXpath); System.out.println("Country " + k +" :"+ driver.findElement(By.xpath(printXpath)).getText()); } //Thread.sleep(10000); } }
You can use something like that for scrolling up/down.Just specifying the coordinates
JavascriptExecutor jse=(JavascriptExecutor)driver;
jse.executeScript(“window.scrollBy(0,250)”,””);