Found 519 Articles for Selenium

Take screenshot of the options in dropdown in selenium c#.

Debomita Bhattacharjee
Updated on 30-Jan-2021 12:35:45

2K+ Views

We can take screenshots of the options in dropdown with Selenium Webdriver. A screenshot is generally captured for the failure test cases. This is achieved with the help of ITakesScreenshot interface.We shall take the help of GetScreenshot method to grab the screenshot. Finally, the SaveAsFile method is used where we pass the parameters – the path of the file and format of the image.Syntax((ITakesScreenshot)d). GetScreenshot().SaveAsFile("Screenshot.png", ScreenshotImageFormat.Png);For implementation we shall be using the NUnit framework.Exampleusing NUnit.Framework; using OpenQA.Selenium; using OpenQA.Selenium.Firefox; using System; namespace NUnitTestProject1{    public class Tests{       String u ="https://www.tutorialspoint.com/selenium/selenium_automation_practice.htm";       IWebDriver d;     ... Read More

How to connect to an already open browser using Selenium Webdriver?

Debomita Bhattacharjee
Updated on 30-Jan-2021 12:32:52

6K+ Views

We can connect to an already open browser using Selenium webdriver. This can be done using the Capabilities and ChromeOptions classes. The Capabilities class obtains the browser capabilities with the help of the getCapabilities method.This is generally used for debugging purposes when we have a large number of steps in a test and we do not want to repeat the same steps. First of all we shall launch the browser and enter some text in the below edit box.Exampleimport org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.Capabilities; import org.openqa.selenium.By; import java.util.Map; import java.util.concurrent.TimeUnit; public class ConnectBrwSession{    public static void main(String[] ... Read More

Finding an element by partial id with Selenium in C#.

Debomita Bhattacharjee
Updated on 30-Jan-2021 12:27:37

1K+ Views

We can find an element by partial is with Selenium in C#. This can be done as we identify elements with the locator's CSS and xpath. The regular expression is used to find the partially matched element.Let us investigate the id attribute of an element having value as gsc−i−id1.In xpath, we utilize the contains() function for partial matching. So, here xpath expression shall be //*[contains(@id, 'id')]. This is because the subtext id is within the text gsc−i−id1. We can also take the help of the starts−with() function. So, the xpath expression becomes //*[starts−with(@id, 'gsc')] as the text gsc−i−id1 starts with ... Read More

How to get all options in a drop-down list by Selenium WebDriver using C#?

Debomita Bhattacharjee
Updated on 30-Jan-2021 12:23:21

2K+ Views

We can get all options in a drop−down list by Selenium Webdriver in C#. The static drop−down in an html code is identified with a select tag. All the options for a drop−down have the option tag.To obtain all the options in the form of a list, we shall first identify that element with the help of any of the locators like id, xpath, name, and so on. Then we must create an object of the SelectElement class and apply Options method on it.Let us investigate the html code of drop−down.For implementation we shall be using the NUnit framework.Exampleusing NUnit.Framework; ... Read More

How to check if Element exists in c# Selenium drivers?

Debomita Bhattacharjee
Updated on 30-Jan-2021 12:20:16

4K+ Views

We can check if element exists with Selenium webdriver in C#. This can be determined with the help of the FindElements method. It returns a list of elements which matches the locator passed as a parameter to that method.If there are no matching elements, an empty list is obtained. In case we have used the method FindElement instead of FindElements, NoSuchElementException will be thrown if there are no matching elements.For implementation we shall be using the NUnit framework.Exampleusing NUnit.Framework; using OpenQA.Selenium; using OpenQA.Selenium.Chrome; using OpenQA.Selenium.Firefox; using System; using System.Collections.Generic; namespace NUnitTestProject1{    public class Tests{       String u ... Read More

How to use Selenium in C#?

Debomita Bhattacharjee
Updated on 30-Jan-2021 12:17:02

478 Views

We can use Selenium in C#. We should have Visual Studio 2019 installed in the system along with Selenium webdriver and any browser like Firefox, Chrome, and so on. Then we must utilize the NUnit framework.Launch Visual Studio 2019 and then click on Create a new project.Type NUnit in the search box appearing in Create a new project pop−up. Select NUnit Test Project(.NET Core) from the search results.Enter Project name and Location. Then click on Create to proceed.As the project is set up on NUnit(.Net Core), the Setup and Test methods shall be given by default.We should navigate to the ... Read More

How to scroll to element with Selenium WebDriver using C#?

Debomita Bhattacharjee
Updated on 30-Jan-2021 12:12:49

4K+ Views

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.Syntaxvar e = driver.FindElement(By.XPath("//*[text()='Careers']")); ((IJavaScriptExecutor)driver) .ExecuteScript("arguments[0].scrollIntoView(true);", e);For implementation we shall be using the NUnit framework.Exampleusing 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 ... Read More

How to run Selenium tests in multiple browsers one after another from C# NUnit?

Debomita Bhattacharjee
Updated on 30-Jan-2021 12:10:16

390 Views

We can run Selenium tests in multiple browsers one after another from C# NUnit. This is done with the help of the Test Fixture concept. This is an attribute that identifies a class, step up and tear down methods.There are some rules to be followed for a class to have a fixture −It should not be of type abstract.There should be a default constructor for a non−parameterized fixture.The parameterized fixture should have a constructor.It can be publicly exported.Exampleusing NUnit.Framework; using OpenQA.Selenium using OpenQA.Selenium.Chrome; using OpenQA.Selenium.Firefox; using System; namespace NUnitTestProject1{    //Test Fixture declaration    [TestFixture(typeof(FirefoxDriver))]    [TestFixture(typeof(ChromeDriver))]    public class ... Read More

How to enable cookie in phantomjsdriver selenium c#?

Debomita Bhattacharjee
Updated on 30-Jan-2021 12:08:37

172 Views

We can enable cookie with Selenium Webdriver in C#. A cookie is the data stored by the browser. A key−value pair is used to store the information in cookies to hold the relevant information.To add a cookie, the method AddCookie is used. The key and value of the cookie are passed as parameters to the method. Also, to obtain the cookie information, GetCookieNamed method is used.Syntaxdriver.Manage().Cookies.AddCookie(new Cookie("Automation", "QA")); driver.Manage().Cookies.GetCookieNamed("Automation");For implementation we shall be using the NUnit framework.Exampleusing NUnit.Framework; using OpenQA.Selenium; using OpenQA.Selenium.Firefox; using System; namespace NUnitTestProject1{    public class Tests{       String u = "https://www.tutorialspoint.com/index.htm";       ... Read More

Selenium versus BeautifulSoup for Web Scraping.

Debomita Bhattacharjee
Updated on 30-Jan-2021 12:06:08

226 Views

We can perform web scraping with Selenium webdriver and BeautifulSoup. Web Scraping is used to extract content from a page. In Python, it is achieved with the BeautifulSoup package.Let us scrap and get the below links on a page −Let us also see the html structure of the above links −Let us see how to do web scraping with BeautifulSoupTo install the required package for Beautifulsoup, we should run the below commands −pip install bs4 pip install requestsExamplefrom bs4 import BeautifulSoup import requests #get all response d=requests.get("https://www.tutorialspoint.com/about/about_careers.htm") #response content whole page in html format s = BeautifulSoup(d.content, 'html.parser') #access to ... Read More

Advertisements