Technology, Smartphones, Games

OpenQA Selenium C# samples

OpenQA Selenium C samples

Selenium is a browser automation framework and ecosystem. Iwas working on a project based on this. You can add it to your C# project from GitHub. Here are few samples which I used in my code.

If the element you want to process is not visible in the screen it may throw exception. the object driver used in the below codes are IWebDriver object. Here is How to scroll down to an element in the browser window

IWebElement oElement =  driver.FindElement(By.LinkText(“LINK TEXT”));

JavaScriptExecutor oJS = (IJavaScriptExecutor)driver;

oJS.ExecuteScript("arguments[0].scrollIntoView(true);", oElement );

By.LinkText can be replaced by By.Id or other methods


How to perform a click event

Actions oClick= builder.MoveToElement(driver.FindElements(By.Id("ID OF THE ELEMENT"))[0]).Click();


How to enter a text to text box

IWebElement oTextBox= driver.FindElement(By.Id("TextBox ID"));

oTextBox.SendKeys(“TEXT to ENTER”);

How to select an item from Dropdown (Select)

SelectElement oSelect = new SelectElement(driver.FindElement(By.Id("ID OF DROPDOWN")));

oSelect.SelectByText("TEXT to SELECT");

Hope these codes will help you. Will add more.

Related Posts