Reputation: 65
I need to move down using scrollbar on a web page using selenium webdriver
I used 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 its not moving down...xpath is changing as per position of scrollbar...
Upvotes: 1
Views: 54103
Reputation: 1
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().perform();
This code worked for me with following corrections.
It worked as charm. Thanks for the code.
Upvotes: 0
Reputation: 1
For Java the code is below:
public void moveOverElement(WebElement element)
{
Actions actions = new Actions(driver);
actions.clickAndHold(element).moveByOffset(0,5000).release().perform();
}
For definition WebElement, for the webelement you have to define only the path:
@FindBy (xpath = ".//*[contains(@class, 'link-name') and text() = 'QAEbox']")
private WebElement createdQABoxElement;
Upvotes: 0
Reputation: 1
By
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);
For scroll up:
scrollUp.sendKeys(Keys.PAGE_DOWN);
Upvotes: -1
Reputation: 52
JavascriptExecutor js=(JavascriptExecutor)driver;
js.executeScript("window.scrollBy(0,100)");
Upvotes: 0
Reputation: 529
My code is in python..hope it might help you and you can reproduce the same to 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()
Upvotes: 1
Reputation: 7018
If you are trying to locate some element by scrolling down,the following code will scroll until the element is in view.
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
Upvotes: 4