SeleniumInterviewQuestion InterviewBit
SeleniumInterviewQuestion InterviewBit
© Copyright by Interviewbit
Contents
39. Can you capture a screenshot using Selenium? If yes, write a simple code to
illustrate the same.
40. Explain different types of framework and connection of Selenium with Robot
Framework.
41. Demonstrate usage of Selenium through a test application.
42. Explain basic steps of Selenium testing and its widely used commands via a
practical application.
43. What do you understand about the Page Object Model in the context of
Selenium? What are its advantages?
44. What is Jenkins and what are the benefits of using it with Selenium?
45. How will you select a date from a datepicker in a webpage using Selenium for
automated testing? Explain with a proper code.
46. What do you understand about broken links? How can you detect broken links in
Selenium? Explain properly with code.
47. What do you understand about window handle in the context of automated
testing? How can you handle multiple windows in Selenium?
Introduction
Selenium is a widely used open-source tool for automating web browsers. It allows
developers to create scripts that can interact with web pages in a similar way to how
a human user would. This makes it an invaluable tool for testing web applications
and automating repetitive tasks.
In this article, we will be discussing a range of Selenium Interview Questions and
Answers. These questions are designed to test your knowledge of Selenium, as well
as your ability to think critically and solve problems. We will cover topics such as
Selenium components, common challenges faced while using Selenium, and best
practices for using Selenium in real-world scenarios.
Whether you are an experienced Selenium developer or just starting out, this article
will provide valuable insights and tips to help you succeed in your next Selenium
interview. So let's dive in and explore some of the most common Selenium interview
questions and answers which are categorised in the following sections:
Selenium Interview Questions for Freshers
Selenium Interview Questions for Experienced
Selenium WebDriver Interview Questions
Selenium Tricky Interview Questions
Selenium MCQ Questions
The language used for writing test scripts in Selenium IDE is called Selenese. It is a set
of commands used to test your web application or system. Selenium commands
could be divided into 3 major categories:
Actions: These are the commands interacting directly with web applications.
Accessors: These are the commands which allow users to store values in a user-
defined variable.
Assertions: They enable a comparison of the current state of the application
with its expected state.
ID
ClassName
Name
TagName
LinkText
PartialLinkText
Xpath
CSS Selector
DOM.
Here, we can locate an input having id = ‘email’ present anywhere in the document
object model (DOM).
findElement() findElements()
Syntax − List<WebElement>
Syntax − WebElement button =
buttons =
webdriver.findElement(By.name("
webdriver.findElements(By.name("
<<Name value>>"));
<<Name value>>"));
Using findElements() :-
// JAVA
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;
public class findElements {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\vaibhav\\Desktop\\Java\\
WebDriver driver = new ChromeDriver();
String url = "https://www.exampleurl.com/example.htm";
driver.get(url);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Explanation - In the above code, first of all, we import all the necessary headers and
then set up the driver for the chrome browser. We use the findElements() method
to find all the values present in the 2nd row of a table in the given URL web page
using the XPath of the element.
Using findElement() :-
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;
public class findTagname {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\vaibhav\\Desktop\\Jav
WebDriver driver = new ChromeDriver();
String url = "https://www.exampleurl.com/example.htm";
driver.get(url);
driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);
driver.findElement(By.cssSelector("input[id='search']")).sendKeys("Selenium"); //U
driver.close();
}
}
Explanation - In the above code, first of all, we import all the necessary headers and
then set up the driver for the chrome browser. We use the findElement() method to
find an input element having an id attribute set as search.
15. In Selenium, how will you wait until a web page has been
loaded completely?
There are two methods of making sure that the web page has been loaded
completely in Selenium.
They are as follows:
1. Immediately a er creating the webdriver instance, set an implicit wait:
temp = driver.Manage().Timeouts().ImplicitWait;
On every page navigation or reload, this will try to wait until the page is fully loaded.
2. Call JavaScript return document.readyState till "complete" is returned a er page
navigation. As a JavaScript executor, the web driver instance can be used.
Code example:
The Selenium Server (Selenium RC) acts as a client-configured HTTP proxy and
"tricks" the browser into believing that Selenium Core and the web application being
tested come from the same origin.
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class TakeScreenshot {
WebDriver drv;
@ Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
drv.get("https://google.com");
}
@ After
public void tearDown() throws Exception {
drv.quit();
}
@ Test
public void test() throws IOException {
// Capture the screenshot
File scrFile = ((TakeScreenshot)drv).getScreenshotAs(OutputType.FILE);
// Code for pasting screenshot to a user-specified location
FileUtils.copyFile(scrFile, new File("C:\\Screenshot\\Scr.jpg"))
}
}
package scalerAcademy;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.WebDriver;
public class MyFirstTestClass {
public static void main(String[] args) throws InterruptedException {
//It sets the system property to the given value.
System.setProperty("webdriver.gecko.driver","D:\\Softwares\\geckodriver.exe”);
WebDriver driver = new FirefoxDriver();
driver.get("https://www.google.com/");
//Launch website in the browser
driver.manage().window().maximize();
//The sleep pauses the execution of the thread for 5000 ms.
Thread.sleep(5000);
driver.quit();
}
}
Once you run the above script in a Java IDE, you’ll get the following execution logs
displayed in your IDE window.
Firefox:
WebDriver driver = new FirefoxDriver();
Chrome:
WebDriver driver = new ChromeDriver();
Safari Driver:
WebDriver driver = new SafariDriver();
Internet Explorer:
WebDriver driver = new InternetExplorerDriver();
Navigate to URL:
driver.get(“https://www.interviewbit.com”)
driver.navigateo.to(“https://www.interviewbit.com”)
Refresh page:
driver.navigate().refresh()
Navigate forward in browser history:
driver.navigate().forward()
Navigate backward in browser history:
driver.navigate().backward()
3. Locating an HTML element on the webpage: To interact with a web element and
perform actions on it like clicking a button or entering text, we first need to locate
the desired elements such as the button or the textbox on the web page. The
following are the most commonly used commands for web element navigation:
Locating by ID:
driver.findElement(By.id("q")).sendKeys("Selenium 3");
Location by Name:
driver.findElement(By.name("q")).sendKeys ("Selenium 3");
Location by Xpath:
driver.findElement(By.xpath("//input[@id==’q’])).sendKeys("Selenium 3");
Locating Hyperlinks by Link Text:
driver.FindElement(By.LinkText("edit this page")).Click();
Locating by ClassName
driver.findElement(By.className("profileheader"));
Locating by TagName
driver.findElement(By.tagName("select')).click();
Locating by LinkText
driver.findElement(By.linkText("NextPage")).click();
Locating by PartialLinkText
driverlindElement(By.partialLinkText(" NextP")).click();
Entering a username
usernameElement.sendKeys("InterviewBit");
Entering a password
passwordElement.sendKeys("Raw");
Submitting a text input element
passwordElement.submit();
Submitting a form element:
formElement.submit();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Explicit Wait: This type of wait condition sets an expected condition to occur on the
web page or a maximum wait time for all the webdriver interactions. Eg:
6. Running tests and recording their results using a test framework: in this step,
we run tests in an automated test script to evaluate an application's function and
performance. Various test frameworks are used for this step, such as:
1. JUnit for Java
2. NUnit for C#
3. Unittest or Pyunit for Python
4. RUnit for Ruby
Most frameworks use some sort of asset statement to verify their test results from
the expected results. Eg:
driver.quit();
The following is an example of an app that covers all the steps mentioned above:
import org.openqa.selenium.By,
import org.openqa.selenium.WebElement,
import org.openqa.selenium.support.ni.ExpectedConditiof, import org.openqa.selenium.sup
import org.junit.Assert;
public class Example {
public static void main(String[] args) {
// Creating a driver instance
WebDriver driver = new FirefoxDriver(),
// Navigate to a web page
driver.get("http://www.foo.com");
// Enter text to submit the form
WebElement usernameElement = driver.findElement( By.name("username"));
WebElement passwordElement = driver.findElement(By.name(”password"));
WebElement formElement = driver.findElement(By.id(”loginForm"));
usernameElement.sendKeys("Scaler Academy");
passwordElement.sendKeys("Raw");
formElement.submit(); // submit by form element
The following are the advantages of the Page Object Model (POM) :
According to the Page Object Design Pattern, user interface activities and flows
should be separated from verification. Our code is clearer and easier to
understand as a result of this notion.
The second advantage is that the object repository is independent of test cases,
allowing us to reuse the same object repository with different tools. For
example, we can use Selenium to combine Page Object Model with TestNG/JUnit
for functional testing and JBehave/Cucumber for acceptability testing.
Because of the reusable page methods in the POM classes, code gets less and
more efficient.
Methods are given more realistic names that can be easily associated with the UI
operation. If we land on the home page a er clicking the button, the function
name will be 'gotoHomePage()'.
Jenkins generates a list of all changes made in SVN repositories, for example.
Jenkins gives permanent links to the most recent build or failed build, which can
be utilized for convenient communication.
Jenkins is simple to install using either a direct installation file (exe) or a war file
for deployment via the application server.
Jenkins can be set up to send the content of the build status to an email
address.
Simple Configuration: Jenkins makes it simple to set up multiple tasks.
Jenkins can be configured to run the automated test build on TestNg following
every SVN build.
Jenkins documents the details of the jar, its version, and the mapping of build
and jar numbers.
Plugins: Jenkins can be set to utilize features and additional functionality
provided by third-party plugins.
Following are the reasons we use Jenkins with Selenium:
When you run Selenium tests in Jenkins, you can run them every time your
program changes, and when the tests pass, you may deploy the so ware to a
new environment.
Jenkins may execute your tests at a predetermined time.
The execution history as well as the Test Reports can be saved.
Jenkins allows you to develop and test a project in continuous integration using
Maven.
Here, we will be using the chrome browser and so we will be implementing the code
for the chrome browser only. You can implement similar code for firefox and other
browsers as well.
First of all, we create a package named browserSelection which contains a class
defined for handling different types of browsers such as chrome, firefox that we may
want to use.
package browserSelection;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class SelectBrowser
{
static WebDriver driver;
public static WebDriver useChrome()
{
System.setProperty("webdriver.chrome.driver", "E:\\SeleniumLibs\\\\chromedriver_wi
driver = new ChromeDriver();
driver.manage().window().maximize();
return driver;
}
}
Next, we create a package named datepicker which will contain a class containing
methods defined for selecting a specific date on the website of MakeMyTrip. We need
to import this package into our driver class and call the respective methods.
package datepicker;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.WebElement;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import browserSelection.SelectBrowser;
public class DatePick
{
WebDriver driver;
@BeforeMethod
public void startBrowser()
{
driver = SelectBrowser.useChrome();
}
@Test
public void selectDateUtil() throws InterruptedException, AWTException
{
//Modify Wait time as per the Network Ability in the Thread Sleep method
driver.get("https://www.makemytrip.com/");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Thread.sleep(5000);
try
{
driver.findElement(By.xpath("//input[@id='hp-widget__depart']")).click();
Thread.sleep(2000);
Date sampleDate = new Date(); // initialising the date object with the current
SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM yyyy");
String date = formatter.format(sampleDate); // formatting the date object in dd
String splitter[] = date.split("-");
String monthYear = splitter[1]; // storing the month and year concatenated stri
String day = splitter[0]; // storing the day number in the current date
System.out.println(monthYear);
System.out.println(day);
In the above code, the function startBrowser() is used to invoke the useChrome()
method from the imported package browserSelection. The function
selectDateUtil() is used to select the current date from the date picker of the
sample web page. The endBrowser() function is used to close the driver
connections by invoking the quit() method.
You should always check for broken links on your site to ensure that the user does
not end up on an error page. If the rules aren't updated appropriately, or the
requested resources aren't available on the server, the error will occur. Manual link
checking is a time-consuming task because each web page may have a huge number
of links, and the process must be performed for each page.
To find broken links in Selenium, follow the instructions below.
Using the <a> (anchor) tag, collect all of the links on a web page.
For each link, send an HTTP request.
Make that the HTTP response code is correct.
Based on the HTTP response code, determine whether the link is genuine or not.
Repeat the procedure for all of the links that were captured in the first step.
package SeleniumPackage;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Iterator;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class BrokenLinks {
driver.manage().window().maximize();
driver.get(pageURL);
Iterator<WebElement> it = links.iterator();
// Iterating over the obtained list of elements and checking them one by one
while(it.hasNext()){
url = it.next().getAttribute("href");
System.out.println(url);
if(!url.startsWith(pageURL)){
System.out.println("URL belongs to another domain, skipping it.");
continue;
}
try {
huc = (HttpURLConnection)(new URL(url).openConnection());
huc.setRequestMethod("HEAD");
Explanation - In the above code, we first set up the system properties and then
initialize a webdriver object. We find all the elements in the web page having the
anchor tag with the help of the findElements() method. Then, we iterate over the
list obtained one by one and fire up the URL and read the response code received to
check if it is a broken link or not.
package SeleniumPackage;
import java.util.Iterator;
import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class WindowHandle_Demo {
public static void main(String[] args) throws Exception {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\user\\Downloads\\seleniu
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
// Loading the website
driver.get("http://www.interviewbit.com/");
String parent=driver.getWindowHandle(); // storing the parent window name as a str
List<WebElement> links = driver.findElements(By.tagName("a")); // storing the list
Iterator<WebElement> it = links.iterator();
// Iterating over the list elements one by one and clicking all the links to open
while(it.hasNext()){
it.next().click();
}
Set<String> s = driver.getWindowHandles(); // Storing the list of all the child wi
Iterator<String> I1= s.iterator();
// Iterating over the list of child windows
while(I1.hasNext())
{
String child_window=I1.next();
if(!parent.equals(child_window))
{
driver.switchTo().window(child_window);
System.out.println(driver.switchTo().window(child_window).getTitle());
driver.close();
}
}
//switch to the parent window
driver.switchTo().window(parent);
}
}
In the above code, we open the landing page of interviewbit and then find all the
elements having the anchor tag and click them to open multiple child windows.
Then, we iterate over each of the child windows and print them as a string. Finally,
having traversed over the entire list, we break from the loop and switch back to the
parent window.
1. Implicit Wait: Implicit wait instructs Selenium to wait a specified amount of time
before throwing a "No such element" exception (One of the WebDriver Exceptions is
NoSuchElementException, which occurs when the locators indicated in the Selenium
Program code is unable to locate the web element on the web page).
Before throwing an exception, the Selenium WebDriver is told to wait for a particular
amount of time. WebDriver will wait for the element a er this time has been set
before throwing an exception. Implicit Wait is activated and remains active for the
duration of the browser's open state. Its default setting is 0, and the following
protocol must be used to define the specific wait duration.
Its Syntax is as follows:
driver.manage().timeouts().implicitlyWait(TimeOut, TimeUnit.SECONDS);
2. Explicit Wait: Explicit wait tells the WebDriver to wait for specific conditions
before throwing an "ElementNotVisibleException" exception. The Explicit Wait
command tells the WebDriver to wait until a certain condition occurs before
continuing to execute the code. Setting Explicit Wait is crucial in circumstances when
certain items take longer to load than others.
If an implicit wait command is specified, the browser will wait the same amount of
time before loading each web element. This adds to the time it takes to run the test
script. Explicit waiting is smarter, but it can only be used for specific parts. It is,
nonetheless preferable to implicit wait since it allows the programme to stop for
dynamically loaded Ajax items.
Its Syntax is as follows:
3. Fluent Wait: It is used to inform the WebDriver how long to wait for a condition
and how o en we want to check it before throwing an "ElementNotVisibleException"
exception. In Selenium, Fluent Wait refers to the maximum amount of time that a
Selenium WebDriver will wait for a condition (web element) to become visible.
It also specifies how o en WebDriver will check for the presence of the condition
before throwing the "ElementNotVisibleException." To put it another way, Fluent
Wait searches for a web element at regular intervals until it timeouts or the object is
found. When engaging with site items that take longer to load, Fluent Wait
instructions come in handy. This is a common occurrence with Ajax apps. It is
possible to establish a default polling period while using Fluent Wait. During the
polling time, the user can configure the wait to ignore any exceptions. Because they
don't wait out the complete duration defined in the code, fluent waits are also
known as Smart Waits.
Its Syntax is as follows:
On a high level, the Selenium webdriver communicates with the browser and does
not transform commands into JavaScript. Our Java or Python code will be
transmitted as an API get and post request in the JSON wire protocol. The browser
webdriver interacts with the real browser as an HTTP Request, as mentioned in the
previous answer. To receive HTTP requests, each Browser Driver utilizes an HTTP
server. When the URL reaches the Browser Driver, it will send the request via HTTP to
the real browser. The commands in your Selenium script will be executed on the
browser a er this is completed.
If the request is a POST request, the browser will perform an action. If the request is a
GET request, the browser will generate the corresponding response. The request will
then be delivered to the browser driver through HTTP, and the browser driver will
send it to the user interface via JSON Wire Protocol. Learn More.
The JSON wire protocol converts test commands into HTTP requests.
Every browser has its own driver that initializes the server before executing any
test cases.
The browser's driver then begins to receive the request.
Selenium WebDriver Listeners, as the name implies, "listen" to any event that the
Selenium code specifies. Listeners are useful when you want to know what happens
before you click any element, before and a er you navigate to an element, or when
an exception is thrown and the test fails. Listeners can be used in Selenium
Automation Testing to log the order of activities and to capture a screenshot
whenever an Exception is thrown. This makes debugging easier in the later stages of
Test Execution. Some examples of Listeners are Web Driver Event Listeners and
TestNG.
The essential information may show on the web page without refreshing the browser
when you click on a submit button. It may load in a fraction of a second, or it may
take longer. We have no control over how long it takes for pages to load. In Selenium,
the easiest way to deal with circumstances like this is to employ dynamic waits (i.e.,
WebDriverWait in combination with ExpectedCondition)
The following are some of the approaches that are available:
1. titleIs() – The anticipated condition looks for a specific title on a page.
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("xpath")));
wait.until(ExpectedConditions.alertIsPresent())!=null);
wait.until(ExpectedConditions.textToBePresentInElement(By.id("text"),"text to be found"
java -jar <selenium server standalone jar name> -host <Your IP Address>
2. Port number: TCP/IP port for connecting Selenium tests to the Selenium Grid Hub.
4444 is the default port hub.
The Syntax is as follows:
java -jar <selenium server standalone jar name> -role hub -port 4444
Assure this port isn't being used by any other so ware on your machine. An exception
like Exception in thread "main" java.net may occur. Selenium is already running on
port 4444. BindException: Selenium is already running on port 4444. Alternatively,
some other service is available.
If this happens, you may either kill the other process using port 4444 or tell Selenium-
Grid to use a new port for its hub. If you want to change the hub's port, the -port
option can be used.
3. Browser: For the execution of the selenium scripts I required a browser to be
passed.
instead of creating
We may use the same driver variable to work with any browser we want, such as
IEDriver, SafariDriver, and so on if we construct a reference variable of type
WebDriver.
The Thread.sleep() method allows you to suspend the execution for a specified
amount of time in milliseconds. If we use WebDriver waits in conjunction with the
Thread.sleep() method, the webdriver will pause the execution for the provided
amount of time in the parameter of the Thread.sleep() function before proceeding
to the next wait. If we combine both waits, the test execution time will increase.
64. How can I type text into the text box without using the
sendKeys() function?
We can use the following piece of code to type text into the text box without using
the sendKeys() function:
// To initialize js object
JavascriptExecutor JS = (JavascriptExecutor)webdriver;
// To enter username
JS.executeScript("document.getElementById('User').value='InterviewBit.com'");
// To enter password
JS.executeScript("document.getElementById('Pass').value='tester value'");
package interviewBit;
// package name
import org.openqa.selenium.By;
import org.testng.annotations.Test;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.WebDriver;
// importing the necessary libraries
// Test class
public class Test {
@Test
public void testmethod(){
// sets the property as required
System.setProperty("webdriver.chrome.driver","C:\\Selenium Environment\\Drivers\\chrom
//Creates a new Chrome Web Driver
WebDriver driver = new ChromeDriver();
driver.get("https://www.youtube.com");
String textAvailable=driver.findElement(By.xpath("//*[@id='gbw']/div/div/div[1]/div[1]/
System.out.println("Textual Matter which is Present is :" + textAvailable);
}
}
Selenium Program:
Output:
valueSeleniumWebDriver
driver.findElement(By.id("form")).submit();
driver.findElement(By.xpath("xpath")).sendKeys(Keys.ENTER);
(JavascriptExecutor(driver)).executeScript("document.getElementsByClassName(ElementLoca
try {
driver.get("www.interviewbit.com");
}catch(Exception e){
System.out.println(e.getMessage());
}
It is worth noting that Selenium alone is not enough for responsive web design
testing, it should be combined with other methods such as manual testing, visual
testing, and using responsive design testing tools to get complete coverage.
Mobile testing: Selenium has limited support for mobile testing. It can
automate web applications on mobile browsers, but it does not support
automating native mobile applications.
Visual testing: Selenium is mainly used for functional testing, but it does not
have built-in support for visual testing. Visual testing compares the look and feel
of the application to a pre-approved design and helps in identifying issues
related to layout, alignment, and font.
Cross-browser testing: Selenium supports a wide range of browsers, but there
are still some browsers that are not fully supported or have limited support.
Test reports and analysis: Selenium's test reporting capabilities are basic and it
does not provide advanced test analytics features like test coverage, flaky test
detection, and root cause analysis.
Performance testing: Selenium is mainly used for functional testing, but it does
not have built-in support for performance testing. Performance testing can help
to measure the responsiveness, stability, and scalability of the application under
test.
Continuous Integration: Selenium does not provide out-of-the-box support for
continuous integration (CI) and continuous delivery (CD) pipeline, it needs to be
integrated with other tools to automate the test execution in CI/CD pipeline.
It's worth noting that Selenium is widely used and has a large community of
developers who are constantly working to improve and extend its capabilities. There
are also many other test automation tools that can be used in combination with
Selenium to address these limitations.
Page Factory is a design pattern used to create an object repository for web elements
in Selenium WebDriver. It's an extension of the Page Object Model design pattern,
which is used to create a centralized repository for web elements. It uses annotations
to identify and initialize web elements at runtime and make the code more readable
and maintainable by separating the test code from the technical details of locating
web elements. In order to use Page Factory, you need to create a class for each web
page and define web elements in that class using the @FindBy annotation it also
contains methods for interacting with the web elements.
Verify that the test is correctly recorded: Make sure that the test is recorded
correctly and that all the elements and commands are in the correct order.
Check the test for syntax errors: Selenium IDE will alert you if there are any
syntax errors in the test, so make sure to check for and fix any errors.
Check the test for compatibility issues: Make sure that the test is compatible
with the browser and version that you are using to run the test.
Check the test for missing elements: Make sure that all the elements used in the
test are present on the web page.
Run the test in debug mode: Selenium IDE provides a debug mode that allows
you to step through the test and check the values of variables and the state of
the web page at each step.
Check the browser's developer tools: The browser's developer tools can be used
to inspect the web page and check for any issues.
Check the log messages: Selenium IDE provides a log panel where you can view
log messages generated by the test. This can be useful for troubleshooting
issues.
Check the Selenium documentation: The Selenium documentation provides
information on the different commands and options available in Selenium IDE,
which can be helpful for troubleshooting.
Finally, you can also seek help from the Selenium community and forums, where
you can ask questions and get help from other Selenium users.
1. Verify that the correct version of Internet Explorer is being used: Selenium
supports different versions of Internet Explorer, so make sure that you are using
a version that is compatible with your Selenium script.
2. Check the Internet Explorer settings: Make sure that Internet Explorer's security
settings are configured correctly and that the browser is not running in
compatibility mode.
3. Check the Selenium WebDriver version: Make sure that you are using the latest
version of the Selenium WebDriver for Internet Explorer.
4. Check the browser's developer tools: Use the browser's developer tools to
inspect the web page and check for any issues.
5. Check the log messages: Selenium provides log messages that can be helpful for
troubleshooting issues.
6. Check the Internet Explorer documentation: The Internet Explorer
documentation provides information on the different options and settings
available in Internet Explorer, which can be helpful for troubleshooting.
7. Use a different browser: If the above steps do not resolve the issue, you may
want to consider using a different browser that is supported by Selenium, like
Firefox or Microso Edge.
8. You can also try to seek help from the Selenium community and forums, where
you can ask questions and get help from other Selenium users.
It's worth noting that, while some browsers may block pop-ups by default, you need
to configure the browser settings to allow pop-ups for the testing website.
It's also important to use explicit waits to handle the dynamic nature of the web
pages and pop-ups, as the time taken for a pop-up window to load may vary
depending on the browser, internet connection, and other factors.
actions.move_to_element(element).click().perform()
The above line of code is an example of using perform() without calling build(). The
move_to_element(), click() methods are chained together and the perform() method
is used to execute all the chained actions.
However, it is important to note that, perform() method is used to execute all the
chained actions only a er calling build() when you are chaining multiple actions
together and want to execute them together.
try:
element.click()
except StaleElementReferenceException:
element = driver.find_element_by_id('element_id')
element.click()
Wait for the element to be available: You can use explicit waits such as
WebDriverWait and ExpectedConditions to wait for the element to be available
before interacting with it.
try:
element.click()
except StaleElementReferenceException:
wait = WebDriverWait(driver, 10)
element = wait.until(EC.presence_of_element_located((By.ID, 'element_id')))
element.click()
Refresh the page: You can refresh the page using the refresh() method of the
WebDriver instance and then re-find the element.
try:
element.click()
except StaleElementReferenceException:
driver.refresh()
element = driver.find_element_by_id('element_id')
element.click()
It is important to note that this exception is a run-time exception, so it's best to catch
it and handle it in the code, rather than letting the script crash.
90. What are test design techniques? Explain BVA and ECP with
some examples.
Test design techniques are the methods or strategies used to design and create test
cases for a so ware application. Some common test design techniques include:
1. Black Box Testing: Testing the functionality of the so ware without looking into
the internal structure or code.
2. White Box Testing: Testing the internal structure or code of the so ware.
3. Grey Box Testing: Combining both Black Box and White Box testing methods.
4. Boundary Value Analysis (BVA): This technique is used to test the so ware's
behaviour at its input and output boundaries. It involves testing the so ware
with input values that are just above and just below the valid range, as well as
testing the so ware with the maximum and minimum valid input values.
5. Equivalence Class Partitioning (ECP): This technique is used to divide the
input domain of the so ware into a finite number of classes or partitions, where
each class represents a group of input values that are expected to behave in the
same way. The goal of ECP is to test the so ware with a representative sample of
input values from each partition.
Examples:
BVA:
1. In a login form, test the minimum and maximum length of the password field.
2. For a form field that accepts a date, testing the so ware with a date that is just
before and just a er the valid range of dates.
ECP:
1. In a form field that accepts a phone number, divide the input domain into three
classes: valid phone numbers, phone numbers that are too short, and phone
numbers that are too long.
2. In a form field that accepts a price, divide the input domain into two classes:
valid prices and invalid prices (e.g., negative prices).
It is important to note that these techniques are helpful in creating a comprehensive
set of test cases that can help ensure that the so ware is functioning correctly.
However, it's not enough to just use one technique, a combination of different
techniques are used to test the so ware in different ways and identify all the possible
defects.
Recommended Resources
Css Interview Questions Laravel Interview Questions Asp Net Interview Questions