- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to scroll to element with Selenium WebDriver using C#?
We can scroll to an element with Selenium webdriver in C#. This is done with the help of JavaScript Executor. Selenium can run JavaScript commands with the help of ExecuteScript method.
The method scrollIntoView in JavaScript is used to perform the scrolling action and the value true is passed as a parameter to the method. This is then passed to the ExecuteScript method.
Syntax
var e = driver.FindElement(By.XPath("//*[text()='Careers']")); ((IJavaScriptExecutor)driver) .ExecuteScript("arguments[0].scrollIntoView(true);", e);
For implementation we shall be using the NUnit framework.
Example
using NUnit.Framework; using OpenQA.Selenium; using OpenQA.Selenium.Firefox; using System; namespace NUnitTestProject1{ public class Tests{ String u = "https://www.tutorialspoint.com/index.htm"; IWebDriver d; [SetUp] public void Setup(){ //creating object of FirefoxDriver d = new FirefoxDriver(); } [Test] public void Test1(){ //launching URL d.Navigate().GoToUrl(u); //identify element var e = d.FindElement(By.XPath("//*[text()='Careers']")); // JavaScript Executor to scroll to element ((IJavaScriptExecutor)d) .ExecuteScript("arguments[0].scrollIntoView(true);", e); Console.WriteLine(e.Text); } [TearDown] public void close_Browser(){ d.Quit(); } } }
Output
Click on Run All Tests button −
Click on Open additional output for this result link −
We should get the Test Outcome and Standard Output.
- Related Articles
- How to scroll down using Selenium WebDriver with Java?
- How to scroll a specific DIV using Selenium WebDriver with Java?
- How to scroll the Page up or down in Selenium WebDriver using java?
- Scroll Element into View with Selenium.
- How to scroll a Web Page using coordinates of a WebElement in Selenium WebDriver?
- How to Scroll Down or UP a Page in Selenium Webdriver?
- How to deal with ModalDialog using selenium webdriver?
- How can I scroll a web page using selenium webdriver in python?
- Scroll element to the middle of the screen with Selenium
- How to scroll down the page till page end in the Selenium WebDriver?
- How to type in textbox using Selenium WebDriver with Java?
- How to get selected option using Selenium WebDriver with Java?
- How to get selected option using Selenium WebDriver with Python?
- How to handle authentication popup with Selenium WebDriver using Java?
- Is it possible to scroll down in a webpage using Selenium Webdriver programmed on Python?

Advertisements