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 21, 2018 in Selenium by kappa3010
• 2,090 points
12,896 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 21, 2018 by king_kenny
• 3,710 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
4,823 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
1,734 views
0 votes
2 answers
0 votes
2 answers

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,500 points
13,494 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,031 views
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,910 points
7,145 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,816 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,710 points
1,307 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,710 points
2,602 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP