Want to go down with the scrolbar selenium webdriver web drive

I need to go down using the scroll bar on a web page using selenium webdriver

I used the following code

Actions dragger = new Actions(driver); WebElement draggablePartOfScrollbar = driver.findElement(By.xpath("/html/body/section[2]/div/div[2]/div/div/div")); int numberOfPixelsToDragTheScrollbarDown = 5000; dragger.moveToElement(draggablePartOfScrollbar).clickAndHold().moveByOffset(0,numberOfPixelsToDragTheScrollbarDown).release().perform(); 

still not moving down ... xpath changes according to the position of the scrollbar ...

+1
c # selenium selenium-webdriver
source share
6 answers

If you are trying to find an item by scrolling down, the following code will scroll until the item appears.

 WebElement element = driver.findElement(By.id("id_of_element")); ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element); Thread.sleep(500); //do anything you want with the element 
+1
source share

My code is in python..hope it can help you and you can reproduce the same with java

 actionChains = ActionChains(driver) option=driver.find_element_by_class_name("mCSB_dragger_bar") actionChains.click_and_hold(option).perform() actionChains.move_by_offset(0,5000).perform() actionChains.release() 

The above code can be simplified as

 actionChains = ActionChains(driver) option=driver.find_element_by_class_name("mCSB_dragger_bar") actionChains.click_and_hold(option).move_by_offset(0,5000).release().perform() 
+1
source share
  JavascriptExecutor js=(JavascriptExecutor)driver; js.executeScript("window.scrollBy(0,100)"); 
0
source share

Across

 scroll=By.xpath("//*[@id='aspnetForm']/center/div/div[2]/table/tbody/tr[2]/td[1]/table/tbody"); WebElement scrollUp = driver.findElement(scroll); scrollUp.sendKeys(Keys.PAGE_DOWN); scrollUp.sendKeys(Keys.PAGE_DOWN); scrollUp.sendKeys(Keys.PAGE_DOWN); scrollUp.sendKeys(Keys.PAGE_DOWN); 

To scroll up:

 scrollUp.sendKeys(Keys.PAGE_DOWN); 
0
source share

For Java, the code is below:

 public void moveOverElement(WebElement element) { Actions actions = new Actions(driver); actions.clickAndHold(element).moveByOffset(0,5000).release().perform(); } 

To define a WebElement for a web element, you only need to define a path:

 @FindBy (xpath = ".//*[contains(@class, 'link-name') and text() = 'QAEbox']") private WebElement createdQABoxElement; 
0
source share

Actions dragger = new actions (driver); WebElement draggablePartOfScrollbar = driver.findElement (By.xpath ("/ html / body / section [2] / div / div [2] / div / div / div")); int numberOfPixelsToDragTheScrollbarDown = 5000; dragger.moveToElement (draggablePartOfScrollbar) .clickAndHold ( draggablePartOfScrollbar ) .moveByOffset (0, numberOfPixelsToDragTheScrollbarDown) .release (). execute ();

This code worked for me with the following fixes.

  1. Having the right xpath. I clicked on the inspect element and right-clicked on the element for xpath and copied.
  2. Add WebElement to clickandHold.
  3. Also make sure that numberOfPixelsToDragTheScrollbarDown matches the exact pixels you want to drag down.

It worked like a charm. Thanks for the code.

0
source share

All Articles