Need to scroll down for locating an Element with Selenium

0 votes
So is there a way to scroll down or up so as to locate an element using XPath? I'm aware of a focus method in Selenium, but it does not physically scroll to within the view of FireFox browser window. I'm doing this because I'm testing the click on an element on a page. But, the event doesn't seem to work unless the element is visible. Does anyone have any suggestions for this?
Apr 20, 2018 in Selenium by kappa3010
• 2,020 points
1,065 views

1 answer to this question.

0 votes

There are a couple of options for doing this. Either use a JavaScript executor method or use Actions() method.

JavaScript Executor method:

JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("javascript:window.scrollBy(250,350)");

Actions method:

WebElement Elmnt = driver.findElement(By.id("my-id"));
Actions actions = new Actions(driver);
actions.moveToElement(Elmnt);
actions.perform()
answered Apr 20, 2018 by king_kenny
• 3,650 points

Related Questions In Selenium

0 votes
0 answers
0 votes
1 answer

Need to select an IFrame with selenium (python)

Well for me, something like this worked. ...READ MORE

answered May 3, 2018 in Selenium by sniffy_god
• 780 points
1,129 views
0 votes
1 answer

Wait for an element to be accessible using Selenium WebDriver

You can try out the below code: ...READ MORE

answered May 18, 2018 in Selenium by Atul
• 10,240 points
152 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,110 points
930 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
1,114 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
853 views
0 votes
1 answer

Need some advise on the preferred element locators with Selenium WebDriver

Well let's not call it "Hierarchy". But, ...READ MORE

answered Apr 13, 2018 in Selenium by king_kenny
• 3,650 points
109 views
0 votes
1 answer

Need to integrate my Selenium tests with REST APIs

Selenium is good enough for this purpose...You ...READ MORE

answered Apr 18, 2018 in Selenium by king_kenny
• 3,650 points
455 views