Locator is a command that tells Selenium IDE which GUI elements (like Text Box, Buttons, Check Boxes etc) we are going to use or perform some automation task.
Different types of locators in Selenium are:-
By.id()
By.name()
By.tagName()
By.className()
By.linkText()
By.partialLinkText()
By.xpath
By.cssSelector()
The Select class in Selenium WebDriver is used for selecting options in a dropdown.We can initialize dropdown by passing the dropdown webElement as parameter to its constructor.
There are three ways to select the dropdown:-
.selectByIndex()
.selectByValue()
.selectByVisibleText()
Example:
WebElement drpdownele = driver.findElement(By.id("idvalue"));
Select dropdown = new Select(drpdownele );
dropdown.selectByIndex(5);
Or
dropdown.selectByVisibleText("Bangalore");
Or
dropdown.selectByValue(“Bangalore”);
3.Describe different kinds of waits in Selenium?
Types of Wait in selenium webdriver are:-
Implicit Wait: It is used to tell the web driver to wait for a certain amount of time before it throws a "No Such Element Exception".
Syntax:
driver.manage().timeouts() .implicitlyWait(1000);
Explicit Wait : Explicit waits stop the execution until the time a particular condition is met or the maximum time has elapsed.
Fluent wait: The Fluent Wait defines the maximum time for the web driver to wait for a condition. We can also set a frequency to check the condition before throwing an "ElementNotVisibleException" exception. It also checks for the web element at regular intervals until the object is not found.
4. How are Selenium Scripts executed?
Steps to be followed to execute Selenium Script using Selenium IDE and Eclipse:-
Install Java JDK
Configure java path in System variables
Install Eclipse and create Eclipse Project
Download and Configure Selenium Jar files
Choses browsers to run
Create Object for Driver
Set System property of Browser
Syntax:
public static void main(String[] args) {
System.setProperty ("webdriver.chrome.driver", "C:\\chromedriver_win32\\ chromedriver.exe");
WebDriver driver = new ChromeDriver();
String baseUrl = "http://demo.guru99.com/ test/newtours/";
}
5. What are advantages and Disadvantages of using Selenium automation tools?
Solution:
Advantages of using Selenium are:
Selenium is an Open Source Software.
Selenium supports various programming languages(like Python, Java, Ruby, pHp etc)
Selenium supports various operating systems (like Windows, Linux, Macintosh etc).
Selenium supports various Browsers (like Mozilla Firefox, Google Chrome, IE, Opera, Safari etc)
Selenium supports Parallel Test Execution.
Disadvantages of using Selenium are:
It supports Web based applications only.
Difficult to use, takes more time to create Test cases.
Limited support for Image Testing.
Difficult to Setup Test Environment when it compares to Vendor Tools like SilkTest etc
6.Describe the Components of selenium?
Selenium components are:
Selenium IDE: Selenium IDE (Integrated Development Environment) is primarily used to develop test cases. Selenium IDE is an easy to use tool from the Selenium Test Suite. We can automate tests for our web applications easily.
Selenium RC: It is a testing framework that enables a QA or a developer to write test cases in any programming language in order to automate UI tests for web applications against any HTTP website.
Selenium WebDriver: It is a widely used component. It is used to overcome the disadvantages of Selenium RC. Selenium WebDriver does not have a server and it communicates with the browser and runs it. It supports multiple OS platforms and browsers.
Selenium Grid: Selenium Grid is a smart proxy server that makes it easy to run tests in parallel on multiple machines. This is done by routing commands to remote web browser instances, where one server acts as the hub. This hub routes test commands that are in JSON format to multiple registered Grid nodes
7. What is the difference between FindElement and FindElements in Selenium?
Selenium defines two methods for identifying web elements:
findElement: A command used to uniquely identify a web element within the web page.
findElements: A command used to identify a list of web elements within the web page.
8. What is the framework in selenium? Describe the various kinds of framework?
Selenium Framework is a code structure that helps to make code maintenance easy. Without frameworks, we will place the “code” as well as “data” in the same place which is neither reusable nor readable.
Using Frameworks, produce beneficial outcomes like increased code re-usage, higher portability, reduced script maintenance cost, higher code readability, etc.
There are mainly three types of frameworks
Data-Driven Test Framework: We need a way to open the Excel sheet and read data from it within our test script. All of our test data is generated from some external files like Excel, CSV, XML or some database table.
Keyword Driven Test Framework: In the keyword-driven test framework, all the operations and instructions are Keyword Driven Framework is a type of Functional Automation Testing Framework which is also known as Table-Driven testing or Action Word based testing. The basic working of the Keyword Driven Framework is to divide the Test Case into four different parts. First is called Test Step, second is Object of Test Step, third is Action on Test Object and fourth is Data for Test Object.
Hybrid Test Framework: It is an easy to use framework which allows manual testers to create test cases by just looking at the keywords, test data and object repository without coding in the framework. Hybrid Driven Framework is a mix of both the Data-Driven and Keyword Driven frameworks.
9.What are xpath and xpath axes methods? Describe the types of xpaths and various xpath axes methods?
Xpath : XPath can be used for both HTML and XML documents to find the location of any element on a webpage using HTML DOM structure.
Types Of XPath In Selenium?
There are two types of XPath
Absolute XPath
Relative XPath
XPath axes : It searches different nodes in XML documents from the current context node. XPath Axes are the methods used to find dynamic elements, which otherwise are not possible by normal XPath methods having no ID , Classname, Name etc.
Various xpath axes methods are:
Ancestor : It specifies the ancestors of the current nodes which include the parents up to the root node.
Child: It specifies the children of the current node.
Parent : It specifies the parent of the current node.
Descendant: It specifies the descendants of the current node i.e. the node's children up to the leaf node(no more children).
Manymore
10. How can you validate text in web pages by using selenium?
There are more than one ways to find it. We can use the getPageSource() method to fetch the full page source and then verify if the text exists there. This method returns content in the form of a string.
We can also check if some text exists with the help of findElements method with xpath locator. Then we shall use the text() function to create a customized xpath. The findElements() method returns a list of elements.