0% found this document useful (0 votes)
3 views11 pages

Selenium Theory

Selenium is an open-source automated testing suite for web applications that supports multiple browsers, platforms, and programming languages. It includes components like Selenium IDE, WebDriver, and Selenium Grid, offering features such as parallel test execution and integration with testing frameworks. However, it has limitations, including a lack of support for desktop applications and the need for programming knowledge to create test scripts.

Uploaded by

Rambabu Namamula
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views11 pages

Selenium Theory

Selenium is an open-source automated testing suite for web applications that supports multiple browsers, platforms, and programming languages. It includes components like Selenium IDE, WebDriver, and Selenium Grid, offering features such as parallel test execution and integration with testing frameworks. However, it has limitations, including a lack of support for desktop applications and the need for programming knowledge to create test scripts.

Uploaded by

Rambabu Namamula
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Selenium Introduction

1. Selenium is a free (open source) automated testing suite for web applications
across different browsers, platforms and programming languages.
2. Selenium can be easily deployed on platforms such as Windows, Linux, Solaris and
Macintosh. Moreover, it supports for mobile applications like iOS and android.
3. Languages supported by Selenium include C#, Java, Perl, PHP, Python and Ruby.
4. Browsers supported by Selenium include Internet Explorer, Mozilla Firefox,
Google Chrome and Safari.
5. Automation testing covers both functional and performance test on an application.

Selenium Features
1. Selenium is a free (open source) automated testing suite for web applications
across different browsers, platforms and programming languages.
2. Selenium IDE provides a playback and record feature for authoring tests without the need
to learn a test scripting language.
3. It helps testers to record their actions and export them as a reusable script with a
simple- to-understand and easy-to-use interface.
4. It also supports parallel test execution which reduces time and increases the efficiency
of tests.
5. Selenium can be integrated with frameworks like Ant and Maven for source ne code
compilation, and can be integrated with testing frameworks like TestNG for
application testing and generating reports.
6. Selenium requires fewer resources as compared to other automation test tools.
7. Selenium web driver does not require server installation, test scripts interact Open
directly with
the browser.

Selenium Limitations
1. Selenium does not support automation testing for desktop applications.
2. Selenium requires high skill sets in order to automate tests more effectively.
3. Since Selenium is open source software, you have to rely on community forums to get
your technical issues resolved.
4. We should know at least one of the supported programming languages to create tests
scripts in Selenium WebDriver.
5. Selenium does not have any inbuilt reportingcapability; you have to rely on plug-ins like
JUnit and TestNG for test reports.
6. It is not possible to perform testing on images.
7. No one is responsible for new features usage; they may or may not work properly.

1/47
Selenium Tool Suite
1. Selenium is not just a single tool but a suite of software's, each catering to different testing
needs of an organization. It has four components.
Selenium Integrated Development Environment (IDE)
Selenium Remote Control (RC) [Now Deprecated]
WebDriver
Selenium Grid

Selenium IDE
1. Selenium Integrated Development Environment (IDE) is the simplest framework in the
Selenium suite and is the easiest one to learn.
2. It is a Firefox/Chrome plugin that you can install as easily as you can with other plugins.
3. However, because of its simplicity, Selenium IDE should only be used as a
prototyping tool.
4. Selenium IDE is implemented as Firefox extension which provides record and
playback functionality on test scripts.
5. It allows testers to export recorded scripts in many languages like HTML, Java, Ruby,
RSpec, Python, C#, JUnit and TestNG. You can use these exported script in Selenium RC
or Webdriver.

Selenium IDE-Installation
1. Open Selenium official website
seleniumhq.org
(https://www.selenium.dev/)
2. Then click on Download Section.
3. In the webpage search for Selenium IDE and click on Chrome to install Google
Chrome plug-in or click on Firefox to install Firefox Plug-in.
4. Restart you browser, go to the top right corner on your browser and look for the
Selenium IDE icon.
5. Click on that icon to launch Selenium IDE.

Selenium IDE-Features
1. Very easy to use and install.
2. No programming experience is requied.
3. Export tests to different programming languages.

Selenium IDE-Limitations
1. Available in only Firefox and Chrome.
2. Designed only to create prototypes of tests.
3. Test execution is slow.

Selenium Webdriver
2/47
1. Selenium WebDriver is the most important component of Selenium Tool's Suite.
2. The initial version of Selenium i.e Selenium v1 consisted of only IDE, RC and Grid.
Selenium WebDriver was first introduced as a part of Selenium v2.0. However, with
the release of Selenium v3, RC has been deprecated and moved to legacy package.
3. In WebDriver, test scripts can be developed using any of the supported programming
languages and can be run directly in most modern web browsers. Languages
supported by WebDriver include C#, Java, Perl, PHP, Python and Ruby.
4. Selenium Web driver is most popular with Java and C#.
5. Selenium WebDriver performs much faster as compared to Selenium RC because it
makes direct calls to the web browsers. RC on the other hand needs an RC server
to interact with the browser.
6. Selenium uses drivers, specific to each browser in order to establish a secure
connection with the browser without revealing the internal logic of browser's functionality.
7. WebDriver is supporting dynamic web pages where elements of a page may
change without the page itself being reloaded.
8. The more pain while doing automation is the handling Javascripts alerts & prompts. The
WebDriver very verse with handle the Javascript alerts, prompts and handling multiple
frames, multiple browser windows.

Selenium WebDriver-
Features Multiple Browser
Support Multiple Languages
Support
Speed
Simple Commands

Selenium WebDriver- Installation


Download and Install Java
Download and Configure Eclipse IDE
Download Selenium WebDriver Java Client
Configure Selenium WebDriver

Selenium WebDriver- First TestCase


Step:1 Launch Eclipse IDE and create a java project as "SeleniumClasses". Then create
a class under this project. We will write our first Selenium test script in the
"BrowserDemo" file under the "SeleniumClasses" test suite.
Step:2 In the second step you have to download driver based on the browser.
For example geckodriver for firefox, chromedriver for googlechrome,
iedriverserver for internetexplorer. You can download these file from the official
website of selenium. Step:3Visit
Selenium Official Website (https://www.selenium.dev/)
and then click on download tab and based on your requirement download any
driver related to your Operating System.
Step:4 Open class which we are created in step 1 and write the code which you want to
3/47
execute.

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class BrowserDemo {

public static void main(String[] args) {

//InternetExplorer
System.setProperty("webdriver.ie.driver", "(2)\\chromedriver.exe");
WebDriver driver = new InternetExplorerDriver();
driver.manage().window().maximize();
driver.get("http://google.com");
System.out.println(driver.getTitle());
System.out.println(driver.getCurrentUrl());

//GoogleChrome
System.setProperty("webdriver.chrome.driver", ""(2)\\chromedriver.exe ");
WebDriver driver2 = new ChromeDriver();
driver2.manage().window().maximize();
driver2.get("http://google.com");
System.out.println(driver2.getTitle());
System.out.println(driver2.getCurrentUrl());

//Firefox
System.setProperty("webdriver.gecko.driver", " geckodriver.exe");
WebDriver driver3 = new InternetExplorerDriver();
driver.manage().window().maximize();
driver3.get("http://google.com");
System.out.println(driver3.getTitle());
System.out.println(driver3.getCurrentUrl());
}
}

1. In selenium, we use System.setProperty("name","value") method because the


browser doesn’t have a built-in server to run the automation code so you will need a
Chrome/IE/Gecko(according to requirement) driver server for communicating your
Selenium code to the browser. In this method we have to pass two parameters, first
parameter is name of the browser which we want to connect and second parameter is the
path of the related driver which we have downloaded in Step 3.

4/47
For example System.setProperty("webdriver.ie.driver", "E:\\Softwares\\
SeleniumDrivers\\IEDriverServer.exe");
2. In the next step we have created a browser object to access and to perform some
operations on that browser. WebDriver defines common methods which all browser
classes (such as Firefox, Chrome etc.,) use. All these class methods are derived from
WebDriver interface.
For example WebDriver driver = new InternetExplorerDriver();
3. The WebDriver provides the window interface for setting up the browser window
size, state, and so on. When we call the maximize() method, the browser window
will be maximized from normal or minimized state.
For example driver.manage().window().maximize();
4. If we want to open a specific URL on that browser we will use get() method. In that
method we have to pass the specific URL.
For example driver.get("http://google.com");
5. If we want to get current page title we wil use driver.gettitle() method and if we want
to get current page URL we will use driver.getCurrentUrl() method.

Locating Web Elements


It is an address that identifies a web element ( say Text Box, Buttons, Check Boxes etc)
uniquely with in the web page.
Identification of correct elements is a prerequisite to creating an automation script. But
accurate identification of elements is more difficult than it sounds.
We have 8 element Locators to recognise Web Elements. The choice of locator depends
largely on your Application Under Test. Those are:
1. By Id: Locates element using id attribute of the web element.
WebElement element =
driver.findElement(By.id("elementId"));
2. By className: Locates the web element using className attribute.
WebElement element =
driver.findElement(By.className("elementsClass"));
3. By tagName: Locates the web element using its html tag like div, a, input etc.
WebElement element = driver.findElement(By.tagName("a"));
4. By name: Locates the web element using name attribute.
WebElement element =
driver.findElement(By.name("male"));
5. By linkText: Locates the web element of link type using their text.
WebElement element = driver.findElement(By.linkText("Click
Here"));
6. By partialLinkText: Locates the web element of link type with partial matching of text.
WebElement element = driver.findElement(By.partialLinkText("Click"));
7. By cssSelector: Locates the web element using css its CSS Selector
patterns WebElement element =
driver.findElement(By.cssSelector("div#elementId"));

5/47
8. By xpath: Locates the web element using its XPaths
WebElement element = driver.findElement(By.xpath("//div[@id=’elementId’]"));
we prefer using id because id of elements are generally unique. But there can be
scenarios where we might not have id attributes of web elements, also other locators like
name, className might not fetch the unique required web element. In those scenarios,
we should use cssSelector and xpath locators.
The sendKeys() method is used to enter the specified value in the textbox.
driver.findElement(By.cssSelector("div#elementId")).sendKeys(“TestSelenium “);
Click() method is used to click on the web element present on the web page.
driver.findElement(By.linkText("Click Here")).click();

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

class LocatorsDemo {
public static void main(String[] args) {

System.setProperty("webdriver.chrome.driver", "E:\\Drivers\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("http://fb.com");

driver.findElement(By.id("email")).sendKeys("9052938526");
driver.findElement(By.name("pass")).sendKeys("password");
driver.findElement(By.className("inputtext")).sendKeys("abhishek@gmail.com");
driver.findElement(By.tagName("input")).sendKeys("751111112222");
driver.findElement(By.partialLinkText("Forgotten")).click();
driver.findElement(By.linkText("Forgotten Password?")).click();
driver.findElement(By.cssSelector("#u_0_q")).sendKeys("99999999");
driver.findElement(By.xpath("//*[@id=\"reg_pages_msg\"]/a")).click();
}
}

Selenium WebDriver Commands


1. Here we will learn some of the basic selenium commands for performing operations like
opening a URL, clicking on buttons, writing in textbox, closing the browser etc.

Browser Commands
get() method: The driver.get() method is used to navigate to a web page by passing the
string URL as parameter.
driver.get("http://facebook.com");
getTitle() method: In WebDriver, this method fetches the title of the current web page.
System.out.println(driver.getTitle());
6/47
getCurrentUrl() method: In WebDriver, this method fetches the string representing the
Current URL of the current web page.
System.out.println(driver.getCurrentUrl());
close() method: The driver.close() command is used to close the browser having focus.
driver.close();
quit() method: The driver.quit command is used to close all the browser instances open.
driver.quit();

Navigation Commands
navigate().to() method: The driver.navigate().to() method does the task of opening a web
page like driver.get() method.
driver.navigate().to("http://youtube.com");
navigate().back() method: Selenium provides navigate().back() command to move
backwards in the browser's history.
driver.navigate().back();
navigate().forward() method: Selenium provides navigate().forward() command to move
forward in a browser.
driver.navigate().forward();
navigate().refresh() method: It is used to refresh a page in Selenium WebDriver.
driver.navigate().refresh();
sendKeys(Keys.F5) method: It is used to refresh a page in Selenium WebDriver on any
textbox on the webpage
driver.findElement(By.id("id123")).sendKeys(Keys.F5);

WebElement Commands
click() method: The click() method in Selenium is used to perform the click operation on
web elements.
driver.findElement(By.id("button1")).click();
sendKeys() method: The sendKeys() method can be used for writing in a textbox or any
element of text input type.
driver.findElement(By.id("firstname")).sendKeys("Abhishek");
clear() method: The clear() method can be used to clear the text written in a textbox or
any web element of text input type.
driver.findElement(By.name("surname")).clear();
getText() method: In automation, many a times we need to fetch the text written over a
web element for performing some assertions or debugging. For this, we have getText()
method in selenium webDriver.
driver.findElement(By.id("email")).getText();
isDisplayed() method: If the element is displayed it will return TRUE otherwise it will
return FALSE.
driver.findElement(By.id("UserName")).isDisplayed();
isEnabled() method: It is used to test whether the element is enabled to perform some
action or not.
driver.findElement(By.id("UserName")).isEnabled();
isSelected() method: It will display TRUE if the element is selected otherwise it will print
FALSE.
7/47
driver.findElement(By.id("Sex-Male")).isSelected();
submit() method: It will submit the webpage to the server.
driver.findElement(By.id("SubmitButton")).submit();

Handling Textboxes in Selenium


1. Basically a textbox is an input tag and will accept character sequence.
2. Input boxes refer to either of these two types:
Text Fields- text boxes that accept typed values and show them as they are.
Password Fields- text boxes that accept typed values but mask them as a series of
special characters (commonly dots and asterisks) to avoid sensitive values to be
displayed.
3. We need to use sendKeys() method to enter data into textbox after identifying the
webelement on the webpage.
driver.findElement(By.id("name")).sendKeys("Abhishek");
4. To clear the textbox we can use clear() method of
selenium. driver.findElement(By.id("name")).clear();
5. We can retrieve value which we have typed or already typed in text box. It will be
useful when we want to verify if correct value is typed or to know existing value in text
box. To retrieve value from text box, we need to use getAttribute("value") method.
driver.findElement(By.id("name")).getAttribute("value");
6. We can also get the type of the text box. For this purpose we use getAttribute("type")
method.
driver.findElement(By.id("name")).getAttribute("type");

Handling Alerts / PopUps in Selenium


1. Alert is a small message box which displays on-screen notification to give the user some
kind of information or ask for permission to perform certain kind of operation. It may be
also used for warning purpose.
2. Selenium WebDriver provides three methods to accept and reject the Alert depending
on the Alert types.
3. We need to use accept() to click on the 'Ok' button of the
alert. driver.switchTo().alert().accept();
4. We can use dismiss() to click on the 'Cancel' button of the
alert. driver.switchTo().alert().dismiss();
5. We need to use getText() to capture the alert
message. driver.switchTo().alert().getText();
6. We can use sendKeys("Text") to send some data to the alert
box. driver.switchTo().alert().sendKeys("Text");

8/47
Handling Dropdown in Selenium
1. The 'Select' class in Selenium WebDriver is used for selecting an option in a
dropdown. The objects of Select type can be initialized by passing the dropdown
webElement as parameter to its constructor.
2. To perform any action, the first task is to identify the element group. I am saying it a
group, as DropDown /Multiple Select is not a single element. They always have a single
name but and they contain one or more than one element in them.
Select dropdown = new Select(driver.findElement(By.name("country")));
3. WebDriver provides three ways to select an option from the drop-down menu.
4. We can use selectByIndex() to select an option based on its index, beginning with
0. dropdown.selectByIndex(5);
5. We need to use selectByValue() to select an option based on its 'value'
attribute. dropdown.selectByValue("India");
6. We can use selectByVisibleText() to select an option based on the text over the
option. dropdown.selectByVisibleText("Database Testing");
7. We can use getOptions( ) to get the all options belonging to the Select tag. It takes
no parameter and returns List<WebElements>.
List <WebElement> options = dropdown.getOptions();
int size=options.size();
System.out.println(size);
for(int i =0; i<size ; i++){
String optValue = options.get(i).getText();
System.out.println(optValue);
}

9/47
Handling Tables in Selenium
1. There are two types of HTML tables published on the web.
Static tables : Data is static i.e. Number of rows and columns are fixed.
Dynamic tables : Data is dynamic i.e. Number of rows and columns are NOT fixed.
2. Handling static table is easy, but dynamic table is a little bit difficult as rows and
columns are not constant.
3. Below tags are generally defined in html tables
: ’table’ tag defines HTML table.
’tbody’ tag defines a container for rows and columns.
’tr’ defines rows in an HTML table.
’td’/’th’ define the column of an HTML table.
4. First get the entire HTML table and store this in a variable of type web element.
WebElement
htmltable=driver.findElement(By.xpath("//*[@id='main']/table[1]/tbody"));
5. Get all the rows with tag name ‘tr’ and store all the elements in a list of web elements.
Now all the elements with tag ‘tr’ are stored in ‘rows’ list.
List<WebElement> rows=htmltable.findElements(By.tagName("tr"));

Handling iFrames in Selenium


1. IFrame is a web page which is embedded in another web page or an HTML
document embedded inside another HTML document.
2. The IFrame is often used to insert content from another source, such as
an advertisement, into a Web page.
3. We cannot detect the frames by just seeing the page or by inspecting.
4. We can identify the iframes using methods given below:
Right click on the element, If you find the option like 'This Frame', 'view Frame
source' or ''Reload Frame' then it is an iframe.
Right click on the page and click 'View Page Source' and Search with the 'iframe', if
you can find any tag name with the 'iframe' then it is meaning to say the page
consisting an iframe.
5. We can even identify total number of iframes by using below
snippet. int size = driver.findElements(By.tagName("iframe")).size();
6. Basically, we can switch over the elements in frames using 2 ways.
7. Switch to the frame by index : Index is one of the attributes for the Iframe through which
we can switch to it. Index of the iframe starts with '0'.
driver.switchTo().frame(0);
8. Switch to the frame by Name or ID : Name and ID are attributes of iframe through which
we can switch to the frame.
driver.switchTo().frame("iframe1");
9. Switch back to the Main Frame : To move back to the parent frame, you can either use
switchTo().parentFrame() or if you want to get back to the main (or most parent) frame,
you can use switchTo().defaultContent();
driver.switchTo().parentFrame();
10/4
driver.switchTo().defaultContent();

11/4

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy