You are on page 1of 17

Selenium

What is Selenium
• Selenium is the portable open source web application testing framework. The
Selenium framework utilizes a default test domain language as “Selenese” for
writing test scripts, it also supports the testers in writing the test scripts. This
framework consists of a varied stack of software test automation tools, each
having different functionality that is application or project specific. Selenium
test suite consists of following:
Selenium feature
• Selenium IDE
• Selenium WebDriver
• Selenium RC or Remote Control
• Selenium-Grid
Platforms and Browsers supported by Selenium
• Google Chrome
• Internet Explorer 7, 8, 9, 10, and 11 on appropriate combinations of Vista, Windows 7,
Windows 8, and Windows 8.1. IE 6 is no longer supported. The driver supports running
32-bit and 64-bit versions of the browser where applicable
• Firefox
• Safari
• Opera
• HtmlUnit
• phantomJS
• Android (with Selendroid or appium)
• iOS (with ios-driver or appium)
Why choose Selenium?
• Transparency: Ensures agility and transparency across the cross-functional teams of
SDLC process (developers, quality assurance, operations, clients and the
management).
• Platform Independent: Avoids the software tester’s time in writing test scripts for
each platform to be tested. As it follows the principle of writing one test script and
runs on any platform.
• Quickens TTM and TTD
In the case of manual testing, the testing is very painful and uncertain process because of
which the product delivery and time to market schedules are missed. This increases the
cost of overall project. However, Selenium avoids testers to write test script for each
platform. This in turn saves the time and also avoids regression testing process. This
optimizes testing time and quickens the TTM and TTD.
Why choose Selenium?
• Fosters Continuous Integration Efforts: Continuous Integration and continuous delivery
are the modern agile-enablers of the software development process. Selenium by automating
the overall test process can act as a catalyst to the nurtures the efforts of organizations to in
successful implementation of Continuous Integration (CI) practice. (Learn how
CI can save the QA efforts here)
• Visibility in End-to-End Testing: In case of end-to-end applications testing selenium offers
great visibility.
• Reduces Turnaround Time: Selenium framework facilitates the testing teams to
automatically run the multiple test cases parallelly on multi-browser platforms. This reduces
the turnaround time by ensuring extreme testing quality.
• Integration With Other Tools: Selenium with Java is famous as rest of the available jars
like ExtentReports, Sikuli, Appium, and so on. Selenium tool provides flexibility for testers
to get integrated with these jars to extend its functionalities to new frontiers:
Selenium setup
• Guide at class
First project
Hide command line
Locating Element
• 1. By ID
• By By.Id(string idToFind) - This is the most efficient
and preferred way to locate an element, as most of the
time IDs are unique. It takes a parameter of String
which is a Value of ID attribute and it returns a BY
object to FindElement() method.
• Command - driver.FindElement(By.Id("Element
ID"));
• If no element has a matching id attribute,
a NoSuchElementException will be raised.
Locating Element
• By Name
• By By.Name(string nameToFind) - This is also an
efficient way to locate an element but again the
problem is same as with ID that UI developer make it
having non-unique names on a page or auto-
generating the names. It takes a parameter of String
which is a Value of NAME attribute and it returns
a BY object to FindElement() method.
• Command - driver.FindElement(By.Name("Element
NAME"));
Locating Element
• By ClassName
• By By.ClassName(string clasNameToFind) - This finds
elements based on the value of the CLASS attribute. It takes a
parameter of String which is a Value of CLASS attribute and
it returns a BY object to FindElement() method.
• Command - driver.FindElement(By.ClassName("Element
CLASSNAME"));
• If an element has many classes then this will match against
each of them.
• Note: This method is a life saver. As said, class can contain
many elements, many times when you end up with duplicate
IDs and Names, just go for the ClassName first and try to
locate the element with ID. That will work fine, as the
selenium will look for the ID which is in the mentioned class.
Locating Element
• By TagName
• By By.TagName(string tagNameToFind) - With this
you can find elements by their TAGNAMES. It takes a
parameter of String which is a Value of TAG attribute
and it returns a BY object to FindElement() method.
• Command -
driver.FindElement(By.TagName("Element
TAGNAME"));
• Locating Element By Tag Name is not too much
popular because in most of cases, we will have other
alternatives of element locators. But yes if there is not
any alternative then you can use element's DOM Tag
Name to locate that element in WebDriver.
Locating Element
• By LinkText & PartialLinkText
• By By.LinkText(string linkTextToFind) - With this you can find
elements of "a" tags(Link) with the link names. Use this when you
know link text used within an anchor tag. It takes a parameter of
String which is a Value of LINKTEXT attribute and it returns a BY
object to FindElement() method.
• By By.PartialLinkText(string partialLinkTextToFind) - With this you
can find elements of "a" tags(Link) with the partial link names.
• Command - driver.FindElement(By.LinkText("Element
LINKTEXT"));
• Command - driver.FindElement(By.PartialLinkText("Element
LINKTEXT"));
• If your targeted element is link text then you can use by link text
element locator to locate that element. Partial Link Text is also same
as Link text, but in this we can locate element by partial link text too.
In that case we need to use By.PartialLinkText at place
of By.LinkText.
Locating Element
• By XPath
• By By.XPath(string xPathToFind)- It is the most popular
and majorly used locating element technique or the
easiest way to locate element in WebDriver. It takes a
parameter of String which is a XPATHEXPRESSION and
it returns a BY object to FindElement() method.
• Command - driver.FindElement(By.XPath("Element
XPATHEXPRESSION"));
• The best thing in xpath is that it provides many different
technique to locate elements. It gives you feature to
locate single element in many ways.
• We have a complete chapter on XPath techniques that
we will come across during our learning journey on
ToolsQA latter.
Difference between FindElement & FindElements Commands
• The difference between FindElement() and FindElements() method is the first returns
a WebElement object otherwise it throws an exception and the latter returns a List
of WebElements, it can return an empty list if no DOM elements match the query.
• FindElement()
• On Zero Match : throws NoSuchElementException
• On One Match : returns WebElement
• On One+ Match : returns the first appearance in DOM
• FindElements()
• On Zero Match : return an empty list
• On One Match : returns list of one WebElement only
• On One+ Match : returns list with all matching instance
Practice
• Launch new Browser
• Open URL http://portal.huflit.edu.vn
• Find “Đăng nhập”
• Click “Đăng nhâp”
• Check logo and elements in Login screen

You might also like