Explore Courses
Liverpool Business SchoolLiverpool Business SchoolMBA by Liverpool Business School
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA (Master of Business Administration)
  • 15 Months
Popular
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Business Administration (MBA)
  • 12 Months
New
Birla Institute of Management Technology Birla Institute of Management Technology Post Graduate Diploma in Management (BIMTECH)
  • 24 Months
Liverpool John Moores UniversityLiverpool John Moores UniversityMS in Data Science
  • 18 Months
Popular
IIIT BangaloreIIIT BangalorePost Graduate Programme in Data Science & AI (Executive)
  • 12 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
upGradupGradData Science Bootcamp with AI
  • 6 Months
New
University of MarylandIIIT BangalorePost Graduate Certificate in Data Science & AI (Executive)
  • 8-8.5 Months
upGradupGradData Science Bootcamp with AI
  • 6 months
Popular
upGrad KnowledgeHutupGrad KnowledgeHutData Engineer Bootcamp
  • Self-Paced
upGradupGradCertificate Course in Business Analytics & Consulting in association with PwC India
  • 06 Months
OP Jindal Global UniversityOP Jindal Global UniversityMaster of Design in User Experience Design
  • 12 Months
Popular
WoolfWoolfMaster of Science in Computer Science
  • 18 Months
New
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Rushford, GenevaRushford Business SchoolDBA Doctorate in Technology (Computer Science)
  • 36 Months
IIIT BangaloreIIIT BangaloreCloud Computing and DevOps Program (Executive)
  • 8 Months
New
upGrad KnowledgeHutupGrad KnowledgeHutAWS Solutions Architect Certification
  • 32 Hours
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Popular
upGradupGradUI/UX Bootcamp
  • 3 Months
upGradupGradCloud Computing Bootcamp
  • 7.5 Months
Golden Gate University Golden Gate University Doctor of Business Administration in Digital Leadership
  • 36 Months
New
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Golden Gate University Golden Gate University Doctor of Business Administration (DBA)
  • 36 Months
Bestseller
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDoctorate of Business Administration (DBA)
  • 36 Months
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (DBA)
  • 36 Months
KnowledgeHut upGradKnowledgeHut upGradSAFe® 6.0 Certified ScrumMaster (SSM) Training
  • Self-Paced
KnowledgeHut upGradKnowledgeHut upGradPMP® certification
  • Self-Paced
IIM KozhikodeIIM KozhikodeProfessional Certification in HR Management and Analytics
  • 6 Months
Bestseller
Duke CEDuke CEPost Graduate Certificate in Product Management
  • 4-8 Months
Bestseller
upGrad KnowledgeHutupGrad KnowledgeHutLeading SAFe® 6.0 Certification
  • 16 Hours
Popular
upGrad KnowledgeHutupGrad KnowledgeHutCertified ScrumMaster®(CSM) Training
  • 16 Hours
Bestseller
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 4 Months
upGrad KnowledgeHutupGrad KnowledgeHutSAFe® 6.0 POPM Certification
  • 16 Hours
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Science in Artificial Intelligence and Data Science
  • 12 Months
Bestseller
Liverpool John Moores University Liverpool John Moores University MS in Machine Learning & AI
  • 18 Months
Popular
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
IIIT BangaloreIIIT BangaloreExecutive Post Graduate Programme in Machine Learning & AI
  • 13 Months
Bestseller
IIITBIIITBExecutive Program in Generative AI for Leaders
  • 4 Months
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
IIIT BangaloreIIIT BangalorePost Graduate Certificate in Machine Learning & Deep Learning (Executive)
  • 8 Months
Bestseller
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Liverpool Business SchoolLiverpool Business SchoolMBA with Marketing Concentration
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA with Marketing Concentration
  • 15 Months
Popular
MICAMICAAdvanced Certificate in Digital Marketing and Communication
  • 6 Months
Bestseller
MICAMICAAdvanced Certificate in Brand Communication Management
  • 5 Months
Popular
upGradupGradDigital Marketing Accelerator Program
  • 05 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Corporate & Financial Law
  • 12 Months
Bestseller
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in AI and Emerging Technologies (Blended Learning Program)
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Intellectual Property & Technology Law
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Dispute Resolution
  • 12 Months
upGradupGradContract Law Certificate Program
  • Self paced
New
ESGCI, ParisESGCI, ParisDoctorate of Business Administration (DBA) from ESGCI, Paris
  • 36 Months
Golden Gate University Golden Gate University Doctor of Business Administration From Golden Gate University, San Francisco
  • 36 Months
Rushford Business SchoolRushford Business SchoolDoctor of Business Administration from Rushford Business School, Switzerland)
  • 36 Months
Edgewood CollegeEdgewood CollegeDoctorate of Business Administration from Edgewood College
  • 24 Months
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with Concentration in Generative AI
  • 36 Months
Golden Gate University Golden Gate University DBA in Digital Leadership from Golden Gate University, San Francisco
  • 36 Months
Liverpool Business SchoolLiverpool Business SchoolMBA by Liverpool Business School
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA (Master of Business Administration)
  • 15 Months
Popular
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Business Administration (MBA)
  • 12 Months
New
Deakin Business School and Institute of Management Technology, GhaziabadDeakin Business School and IMT, GhaziabadMBA (Master of Business Administration)
  • 12 Months
Liverpool John Moores UniversityLiverpool John Moores UniversityMS in Data Science
  • 18 Months
Bestseller
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Science in Artificial Intelligence and Data Science
  • 12 Months
Bestseller
IIIT BangaloreIIIT BangalorePost Graduate Programme in Data Science (Executive)
  • 12 Months
Bestseller
O.P.Jindal Global UniversityO.P.Jindal Global UniversityO.P.Jindal Global University
  • 12 Months
WoolfWoolfMaster of Science in Computer Science
  • 18 Months
New
Liverpool John Moores University Liverpool John Moores University MS in Machine Learning & AI
  • 18 Months
Popular
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (AI/ML)
  • 36 Months
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDBA Specialisation in AI & ML
  • 36 Months
Golden Gate University Golden Gate University Doctor of Business Administration (DBA)
  • 36 Months
Bestseller
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDoctorate of Business Administration (DBA)
  • 36 Months
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (DBA)
  • 36 Months
Liverpool Business SchoolLiverpool Business SchoolMBA with Marketing Concentration
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA with Marketing Concentration
  • 15 Months
Popular
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Corporate & Financial Law
  • 12 Months
Bestseller
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Intellectual Property & Technology Law
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Dispute Resolution
  • 12 Months
IIITBIIITBExecutive Program in Generative AI for Leaders
  • 4 Months
New
IIIT BangaloreIIIT BangaloreExecutive Post Graduate Programme in Machine Learning & AI
  • 13 Months
Bestseller
upGradupGradData Science Bootcamp with AI
  • 6 Months
New
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
KnowledgeHut upGradKnowledgeHut upGradSAFe® 6.0 Certified ScrumMaster (SSM) Training
  • Self-Paced
upGrad KnowledgeHutupGrad KnowledgeHutCertified ScrumMaster®(CSM) Training
  • 16 Hours
upGrad KnowledgeHutupGrad KnowledgeHutLeading SAFe® 6.0 Certification
  • 16 Hours
KnowledgeHut upGradKnowledgeHut upGradPMP® certification
  • Self-Paced
upGrad KnowledgeHutupGrad KnowledgeHutAWS Solutions Architect Certification
  • 32 Hours
upGrad KnowledgeHutupGrad KnowledgeHutAzure Administrator Certification (AZ-104)
  • 24 Hours
KnowledgeHut upGradKnowledgeHut upGradAWS Cloud Practioner Essentials Certification
  • 1 Week
KnowledgeHut upGradKnowledgeHut upGradAzure Data Engineering Training (DP-203)
  • 1 Week
MICAMICAAdvanced Certificate in Digital Marketing and Communication
  • 6 Months
Bestseller
MICAMICAAdvanced Certificate in Brand Communication Management
  • 5 Months
Popular
IIM KozhikodeIIM KozhikodeProfessional Certification in HR Management and Analytics
  • 6 Months
Bestseller
Duke CEDuke CEPost Graduate Certificate in Product Management
  • 4-8 Months
Bestseller
Loyola Institute of Business Administration (LIBA)Loyola Institute of Business Administration (LIBA)Executive PG Programme in Human Resource Management
  • 11 Months
Popular
Goa Institute of ManagementGoa Institute of ManagementExecutive PG Program in Healthcare Management
  • 11 Months
IMT GhaziabadIMT GhaziabadAdvanced General Management Program
  • 11 Months
Golden Gate UniversityGolden Gate UniversityProfessional Certificate in Global Business Management
  • 6-8 Months
upGradupGradContract Law Certificate Program
  • Self paced
New
IU, GermanyIU, GermanyMaster of Business Administration (90 ECTS)
  • 18 Months
Bestseller
IU, GermanyIU, GermanyMaster in International Management (120 ECTS)
  • 24 Months
Popular
IU, GermanyIU, GermanyB.Sc. Computer Science (180 ECTS)
  • 36 Months
Clark UniversityClark UniversityMaster of Business Administration
  • 23 Months
New
Golden Gate UniversityGolden Gate UniversityMaster of Business Administration
  • 20 Months
Clark University, USClark University, USMS in Project Management
  • 20 Months
New
Edgewood CollegeEdgewood CollegeMaster of Business Administration
  • 23 Months
The American Business SchoolThe American Business SchoolMBA with specialization
  • 23 Months
New
Aivancity ParisAivancity ParisMSc Artificial Intelligence Engineering
  • 24 Months
Aivancity ParisAivancity ParisMSc Data Engineering
  • 24 Months
The American Business SchoolThe American Business SchoolMBA with specialization
  • 23 Months
New
Aivancity ParisAivancity ParisMSc Artificial Intelligence Engineering
  • 24 Months
Aivancity ParisAivancity ParisMSc Data Engineering
  • 24 Months
upGradupGradData Science Bootcamp with AI
  • 6 Months
Popular
upGrad KnowledgeHutupGrad KnowledgeHutData Engineer Bootcamp
  • Self-Paced
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Bestseller
KnowledgeHut upGradKnowledgeHut upGradBackend Development Bootcamp
  • Self-Paced
upGradupGradUI/UX Bootcamp
  • 3 Months
upGradupGradCloud Computing Bootcamp
  • 7.5 Months
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 5 Months
upGrad KnowledgeHutupGrad KnowledgeHutSAFe® 6.0 POPM Certification
  • 16 Hours
upGradupGradDigital Marketing Accelerator Program
  • 05 Months
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
upGradupGradData Science Bootcamp with AI
  • 6 Months
Popular
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Bestseller
upGradupGradUI/UX Bootcamp
  • 3 Months
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 4 Months
upGradupGradCertificate Course in Business Analytics & Consulting in association with PwC India
  • 06 Months
upGradupGradDigital Marketing Accelerator Program
  • 05 Months

Must Read 30 Selenium Interview Questions & Answers: Ultimate Guide 2024

Updated on 08 September, 2023

4.11K+ views
24 min read

Introduction

Software testers and developers cannot live without Selenium, an open-source automated testing tool. They get the ability to effectively automate web applications, which helps them save time and effort. This article will give you five inspiring project ideas if you’re a newbie eager to get started with Selenium projects.

Are you attending an important interview and wondering what are all the Selenium interview questions you will go through?

We have created this most-read Selenium interview questions and answers guide to help you understand the depth of the questions and face it with confidence.

These days web apps are on the rise. With the growing need for web apps, there also is an inevitable requirement to test these web apps. That is where Selenium comes into action. Selenium is one of the commonly used automated testing tools which ensures the web app is working just right. If testing was to be done manually, it would utilize several man-hours and would increase the costing as well.

Further, since they are manual, they are prone to errors. Manual testing does not help in the long run, and so, automated testing like Selenium is gaining demand in the industry. If you are pursuing your career in automated testing, and have an upcoming interview in Selenium, this blog is meant for you.

In this blog, we shall discuss here the most common Selenium interview questions. These are for both – the beginners as well as Selenium interview questions for experienced.

Check out our free courses to get an edge over the competition.

Selenium Interview Questions & Answers 2022

Q.1) Why pick Selenium over other automated testing tools?

Selenium is open-source. It is very easy to adapt compared to other automated tools in the market. Due to this reason, many companies picked up Selenium automated testing over other traditional methods. 

Refer to the key attributes of Selenium to understand its vast adaptability-

Key attribute Description
Open Source Platform It is freeware and portable. There are no direct costs involved with Selenium. It can be downloaded for free and gets community-based support. 
Language Support Supports various languages such as Java, Python, Ruby, C# and more. It has its script, but that is not a limitation, as programmers can work with any language.
Browser support  There is a support across multiple browsers such as Chrome, Firefox,Internet Explorer, Opera and more. It becomes useful for programmers while testing. 
Operating Systems Support It can be operated across multiple operating systems such as Windows, OS, Linux, etc. 
Device support Supports tests across devices, as the test can be implemented on Android, iPhone and Blackberry.
Reusability and add-ons The programmers can use scripts that can be tested across multiple browsers. Multiple tests can be executed using Selenium, which covers almost all the aspects of functionality testing by implementing the add-on tools.
Programming languages support It can be integrated with various programming languages and frameworks, such as ANT, Maven, Jenkins, Hudson, and more.

Q.2) List some benefits of Selenium over tools like TestComplete and QTP. Also, what are the disadvantages?

Selenium does not require a license, unlike TestComplete and QTP, being easy on pockets. The online community offers massive support. The release cycles are smaller, and the feedback is prompt compared to TestComplete and QTP. Further, Selenium works on Mac, Linux, and Windows as well. 

On the contrary, Selenium requires a developer to have high coding skills. Whereas QTP and TestComplete require low to moderate level of coding skills, respectively. 

Refer to the below-mentioned table to understand the advantages and disadvantages of Selenium-

Advantages Disadvantages
Open- source software No reliable technical support.
Supports various programming languages Only support web- based applications. 
Supporys multiple operating systems (Android, iOS, etc.) Takes more time test cases.
Supports various browsers (Chrome, Firefox, Safar, Internet Explorer, etc.) Difficult to setup Test Environments
Supports Parallel Test Execution  Limited Image Testing Support
Test cases can be implemented while the browser window is minimised. No built- in reporting facility
Faster than other tools. No test tool integration for executing test management.

Check out upGrad’s Advanced Certification in Blockchain

Q.3) What changes have occurred in the various Selenium version upgrades?

In the first version of Selenium, Selenium v1, it only comprised three suites of tools, which are Selenium IDE, RC, and Grid. The Webdriver was missing. It was only in the second version of Selenium, Selenium v2 that the Webdriver was introduced. Once this was done, Selenium RC was no longer in use.

You can find them in the market, but the support isn’t available. The next version of Selenium is Selenium v3. It consists of Webdriver, IDE, and the Grid. It is currently in use. A newer version, Selenium v4, is also now available.

Selenium IDE is mainly for recording and playing back. The Webdriver is for testing the dynamic web applications using a programming interface. The Grid is used for employing tests in remote host machines. 

You must use the IDE for recording and playback of tests. A WebDriver is used for testing active web applications using a programming interface, and the Grid is employed for deploying tests in isolated host machines.

Refer to the below-mentioned table to understand the difference in various Selenium upgrades-

Selenium Version Description 
Selenium 1
  • Included 3 suite of tools
  • Selenium IDE, Selenium RC, Selenium Grid
  • No webdriver
Selenium 2
  • Seleniium Webdriver
  • Selenium RC not in use.
Selenium 3
  • Selenium IDE
  • Selenium Webdriver
  • Selenium Grid

Check out upGrad: Full Stack Development Bootcamp (JS/MERN)

Q.4) What are the various exceptions in Selenium WebDriver?

Just like any other programming language, you can find exceptions in Selenium as well. You can find the following exceptions in Selenium WebDriver:

TimeoutException: You get this exception when a command does not perform an action in the specified time. 

NoSuchElementException: You get this exception when it cannot find an element with the given attributes on a web page.

ElementNotVisibleException: You get this exception when an element is available in the document object model, but it is not seen on the web page. 

StaleElementException: You get this exception when an element is not attached to the document object model or is deleted. 

NoAlertPresentException: It is a type of popup, which provides important for users. 

NoSuchWindowException: It is a popup that occurs when the driver in the Selenium Program code is unable to find the pop-up window on the web page in order to switch. 

SessionNotFoundException: When the driver is trying to perform operations on the web application after the browser is closed.

InvalidSelectorException: It is a sub class of NoSuchElementException class and occurs when a selector is incorrect or syntactically invalid.

ElementNotSelectableException: It indicates the presence of the web element but not its selectabiity. 

Q.5) Explain Selenium exception test

The exception you expect to be thrown inside a test class is an exception test. If you write a test case intending it to throw an exception, you must use the @test annotation and also mention it in the parameters that which exception would be thrown. For instance, 

@Test(expectedException = NoSuchElementException.class)

Q.6) Is there a need for an excel sheet in a project? Is yes, how? 

Excel sheets are used as a data source during testing. Further, it also stores the data set while executing data-driven testing. When excel sheets are used as a data source, it can store: 

Application URL: Developers can mention the environment URL under which the testing is executed. For example, testing environment, development environment, QA environment, production environment, or staging environment.

User name and password information: Excel sheets can keep safe the access credentials like the username of a password of various environments. Developers can encrypt and store these details for security reasons. 

Test cases: Developers can make a table wherein one column write the test case name and the other which says to be executed or not. 

If you are going to use excel sheets for DataDriven Test, you can easily store the information for various duplications to be executed during the tests. For instance, all the data that needs to be written in a text box for testing on a web page can be stored in the excel sheets. 

It can be defined as the problem that occurs during the test execution. On the occurrence of the exception, the program stops and so does the codes. The codes will not get executed in this scenario.

There exists three types of execution in Selenium-

  1. Checked Exception- Handled during compile time. They cause compile problem if not handled at the right time.
  2. Unchecked Exception- A compiler does not mandate to handle.
  3. Error- Occurs when the scenario becomes fatal and unable to be recover.

upGrad’s Exclusive Software and Tech Webinar for you –

SAAS Business – What is So Different?

Q.7) What is POM? List its advantages?

POM stands for Page Object Model. It is a design pattern for creating an Object Repository for web UI elements. Every single web page in the application must have its own corresponding page class, which is in charge of searching the WebElements in that page and then execute operations on them.

POM in selenium acts as a design pattern that used in test automation creating a object  repository for web UI elements. It assists in reducing the code duplication and improving test maintainence. 

There should be a corresponding Page Class for each web page in the application. The Page Class faciliates in identifying the Web Elements of that particular web page. It also contains the Page methods that performs operations on the WebElements.  This is how to explain how to explain pom in interview.

The advantages of using the Page object model are:

  • It makes the code readable by letting developers separate operations and UI flows from verification. 
  • Several tests can use the same Object Repository because it is independent of Test Cases.
  • The code becomes reusable.

This is how you can tackle pom in selenium interview questions. Now while answering, page object model in selenium interview questions you could also choose to mention the elements of POM. Some of the elements are listed below-

  • Dependencies
  • Resources
  • Plugin tests
  • Plugin configuration
  • Developers and contributors
  • Plugin executions with matching IDs

This is also how to explain page object model framework in interview. You can read the room, and add or deduct from your answers. 

Q.8) What is a Page Factory?

Page Factory offers an enhanced method to execute the Page Object Model by efficiently using the memory, and the execution is done using object-oriented design. 

POM Implementation
With Page Factory Without Page Factory
Uses By() Uses @FindBy()
No imports are required Imports Page factory
No cache storage Cache lookup is faster

 Page Factory initializes the elements of the Page Object or instantiates the Page Objects itself. Annotations for elements can also be produced. It is, in fact, a better way as the describing properties may not be expressive enough to differentiate one object from another.
 

If POM is used without a page factory, instead of having to use ‘FindElements,’ @FindBy is used to look for WebElement, and initElements is used to initialize web elements from the Page Factory class.

@FindBy can accept attributes like tagName, name, partialLinkText , linkText, id, className , css, and xpath.

The Page Factory is a class provided by the Selenium Web Driver to implement the POM. The Page Object Repository is separated from the test methods with the help of Page Factory Concept. 

Some of the other Page Factory annotations-

  • @FindBys
  • @Findall
  • @CacheLookUp

In page object model interview questions, you can definitely expect a question of Page Factory. You may choose to make a slight mention of the Page Factory while responding to what is pom in selenium. Or during pom selenium interview questions, if the interviewer ask a separate question on Page Factory, you may get into depth of it to answer. As mentioned above. Moreover, during the POM interview questions, the interviewer could also twist their way of asking, instead of descriptive questions, they could also throw some MCQs your way, such as the design pattern called page object model mcq.

Q.9) How do you achieve synchronization in WebDriver? Or, tell us about the different types of wait statements Selenium Web Driver?

Synchronization in WebDriver should be achieved using WebDriver Wait. In case a specific element the programmer is working on takes time, then they should use WebDriver Wait.

You can find two wait statements in Selenium web driver, namely, Implicit Wait and Explicit Wait.

Implicit wait commands the WebDriver to wait for a little by polling the DOM. It is present for the complete life of the web driver instance, once the implicit wait is declared. The pre-set value is zero. If you set it more than zero, then the behavior will poll the DOM on a regular basis based on the driver implementation.

Explicit wait commands the execution to wait for a little till a condition is attained like:

  • elementToBeClickable
  • presenceOfElementLocated
  • elementToBeSelected

Read: Spring Interview Questions & Answers

10) What is the use of JavaScriptExecutor?

You can execute JavaScript through Selenium Websriver using JavaScriptExecutor. It is an interface that offers this mechanism. It gives methods like “executescript” and “executeAsyncScript” to run JavaScript in the condition of the currently chosen frame or window. An example of that is:

JavascriptExecutor js = (JavascriptExecutor) driver; 

js.executeScript(Script,Arguments);

It works as an interface which is used to execute JavaScript through Webdriver. The JavaScript Editor provides two methods, namely-

ExecuteScript

These methods are executed in the selected window or frame. This chosen script runs as an anonymous function. The script can return values, the returned data types are-

  • Web Element
  • List
  • String
  • Long
  • Boolean

ExecuteAsyncScript

It is used to execute the asynchronous JavaScript in the current window or frame. It is executed as a single thread while the rest of page is continuously parsing.

Q.11) Which function lets you scroll down a page using JavaScript in Selenium?

The function window.scrollBy() h

elps you scroll down the page using JavaScript in Selenium. For instance:

((JavascriptExecutor) driver).executeScript("window.scrollBy(0,500”)

Q.12) How do you handle mouse and keyboard actions using Selenium?

Special mouse and keyboard actions are handled using Advanced User Interactions API. It comprises of the Actions and the Action Classes that are required for performing these events. The most used mouse and keyboard events are given by Action class are:

dragAndDrop(): This event performs click-and-hold at the position of the source element, moves.

source, target(): Moves to the position of the target element and releases the mouse.

clickAndHold(): It clicks the current location of the mouse.

Q.13) What are various types of Selenium frameworks?

The various types of Selenium frameworks are:

  • Keyword Driven Framework: In this framework, the operations and instructions are written in a separate file like Excel. It is based on keywords that forms the basis of functionality. It might need repetitive writing to perform some actions in case when the code has to cover a lot of functionality. That is why the operators or methods that are required to be performed are written separately from the script in form of keywords.
  • Data-Driven Framework: In this framework, full test data is taken from some external source files like an XML, Excel, CSV, or some other database table. It is based on different datasets that ar ecraeted on externa files such as excel and are imported into the automation testing tool. These datasets are engineered to be kept separate from the original script, thus increasing the accuracy.
  • Hybrid Framework: This framework is a blend of both the Keyword Driven framework and the Data-Driven framework.  The framework uses different keywords and datasets. 

Q.14) Name a few files that serve as a data source for various Selenium frameworks.

They can be an XML, Excel, CSV, or even a Text file.

Q.15) What is Selenese?

Selenese is the group of selenium commands to test a web application. Developers can use Assertions, Actions, and Accessors. Assertions are used as checkpoints. Actions are for running operations, and Accessors are used to store the value of a variable. 

These Selenese commands are used to test web-applications. It can easily verify the presence of an element. There are three types of commands that Selenese uses, such as-

  1. Actions- These commands can change the condition of an application. For example, clicking of a checkbox, form submission, dropdown selection and so on. In case of non-performance, the test fails.
  2. Accessors- These commands verify the state of application. They also keep a track of application. 
  3. Assertions- These commands are used to check the state of applications against the expected conditions.

Q.16) What is the major difference between a Page Factory and Page Object Model (POM)?

A common selenium interview question. A page factory is a method to initialize web elements within the page object on the creation of the instance. On the other hand, the page object model is a class that states the web page and holds its functionalities. 

Q.17) Does Selenium support handling window pop-ups?

No. Selenium does not support handling pop-ups. An alert, which is a pop-up window, displays a warning message on the screen. You can achieve this by using a few methods like: 

Void dismiss(): When the cancel button is clicked in the alert box, this method is called. 

Void accept(): When the ‘OK’ button of the alert is clicked, this method is called. 

String getText(): If you want to capture the alert message, you must call this method. 

Void sendKeys(String stringToSed): If you want to send some information to the alert box, you must call this method. 

Read: React Interview Questions & Answers

Q.18) Explain Robot class

A Robot class gives control over the keyboard and mouse devices.

The methods comprise:

  • KeyPress(): Called on the event where you want to press a key.
  • KeyRelease(): Called in the event to release the pressed key. 
  • MouseMove(): Called in the event when you have to move the mouse pointer in the X and Y coordinates.
  • MousePress(): Called in the event when you press the left button of the mouse.
  • MouseMove(): Called in the event of releasing the pressed button of the mouse.

The Robot Class is used to activate the automated testing for implementation of Java platform. The robot class is easy to implement and can be integrated with an automated framework.

Benefits of Robot Class-

  1. It can simulate the Keyboard and Mouse Event.
  2. Help in  upload/ download of files using the Selenium web driver.
  3. Can easily be integrated with the current automation.

Q.19) How to handle many windows in Selenium?

The window handle is a special identifier that has the address of all the windows. It serves as a pointer to a window returning the value in the string. 

  • get.windowhandle(): It gets the current window handle. 
  • get.windowhandles(): Gets the handles of all the windows opened.
  • switch to: Helps in switching across the windows.
  • set: Sets the window handles, which is in the form of a string.
  • action: helps to execute certain actions on the windows.

Q.20) What are Listeners?

The interface that changes the behavior of the system is called listeners in Selenium. They enable customizations of logs and reports. They are of two kinds: TestNG listeners and Webdriver listeners. 

They have the ability to listen to any event like data entering, page navigation and so on.These are defined with the help of interface. T modifies the behavior of technology and also indulges in providing reports customisation and logs.

Types of listeners in TestNG are mentioned below-

  • Configurable
  • Hookable
  • Reporter
  • Suite Listener
  • Annotation Transformer

Q.21) Explain Assert and Verify commands

Assert: An assertion is used to differentiate between the real result and the expected result. 

Verify: The test executions aren’t paused no matter if the verify condition is true or false. 

Q.22) How does one navigate back and forth on a webpage?

It is one of the most common selenium interview questions.

You can use the below methods to navigate back and forth.

driver.navigate.forward

driver.manage.navigate

driver.manage.back

driver.navigate.to(“url”)

Q.23) How to send ALT/SHIFT/CONTROL key in Selenium WebDriver?

Typically using the keys like ALT, Shift, or Control, we combine them with other keys to activate a function. We cannot just click them alone. We need to define two methods for the purpose of holding onto these keys while the following keys are 

pressed: keyUp(modifier_key) and keyDown(modifier_key) 

Parameters: Modifier_key (keys.ALT or Keys.SHIFT or Keys.CONTROL)

Objective: The purpose is it performs a modifier keypress without releasing the modifier key. Following interactions may assume it’s kept pressed.

Parameters: Modifier_key (keys.ALT or Keys.SHIFT or Keys.CONTROL)

Objective: The purpose is it performs a key release.

So, with a mix of these two methods, we can capture the special function of a particular key.

Q.24) How do we take screenshots in Selenium WebDriver?

The TakeScreenshot function helps to take a screenshot in Selenium Webdriver. Further, you can save the screenshot taking by using getScreenshotAs() method.

File scrFile = ((TakeScreenshot)driver).getScreenshotAs(outputType.FILE);

Q. 25) Can we set the size of the browser window using Selenium? If yes, how? 

Yes. If you wish to maximize the size of browser window, you need to use the code 

driver.manage().window().maximize();

If you wish to resize the current window to a specific dimension, you must use the setSize() method. For instance: 

System.out.println(driver.manage().window().getSize());

Dimension d = new Dimension(420,600);

driver.manage().window().setSize(d);

If you wish to set the window to a particular size, you must use window.resizeTo() method. 

For instance:

((JavascriptExecutor)driver).executeScript("window.resizeTo(1024, 768);");

Q.26) How to select a value from the dropdown? How to handle a dropdown?

You most likely will be asked about a question about dropdown and selection of values as it is a little tricky and technical as well. 

The most crucial detail you must know is that to work with a dropdown in Selenium, it is important to use of the html tag: ‘select’. You cannot handle dropdowns without using the select tag. Have a look at the code below:

<select id="mySelect">

<option value="option1">Cakes</option>

<option value="option2">Chocolates</option>

<option value="option3"> Candies</option>

</select>

In the above code, an HTML ‘select’ tag is used to define a dropdown element. The ID of the select tag here is myselect. We have given three options in the dropdown: Cakes, Chocolates, and Candies. You can see that each of these choices has an attached value attribute. For instance, for Cake, the value is Option1, for Chocolates its Option2, and for Candies, it is Option3. 

To choose a value, you need to:

Identify the ‘select’ html element by using the findelement()

Example:

WebElement mySelectElement = driver.findElement(By.id("mySelect"));

Select dropdown = new Select(mySelectElement);

In the above code, an HTML ‘select’ tag is used to define a dropdown element. The ID of the select tag here is myselect. We have given three options in the dropdown: Cakes, Chocolates, and Candies. You can see that each of these choices has an attached value attribute. For instance, for Cake, the value is Option1, for Chocolates its Option2, and for Candies, it is Option3. 

To choose a value, you need to:

Identify the ‘select’ html element by using the findelement()

Example:

WebElement mySelectElement = driver.findElement(By.id("mySelect"));

Select dropdown = new Select(mySelectElement);

Pick up an option from that dropdown element.

To pick an option from that dropdown, there are three ways:

dropdown.selectByVisibleText(“Chocolates”); → Choosing an option by the text that is seen.

dropdown.selectByIndex(“1”); → Choosing an option using the Index number of that option.

dropdown.selectByValue(“option2”); → Choosing an option using the value of that option.

Note that in all the cases, the option “Chocolates” is selected from the dropdown. Points 1 and 3 are obvious and point two; we say “1” because the indexing starts from zero.

Read: Top Nagios Interview Questions & Answers

Q.27) How do you hop to a new tab which opens up after you click on a link?

On clicking a link on a web page, you need to use the switchTo() command to change the focus of the Webdriver. Example: driver.switchTo().window();

where ‘windowName’ is the name of the window, you want to switch your focus to.

If you do not have the name of the window, you can use the driver.getWindowHandle() command to fetch the name of all the windows that were initiated by the WebDriver. Remember, it will never give you the names of those windows which Webdriver did not initiate. 

On getting the name, you need to run through a loop to get to that window. Here is an example:

String handle= driver.getWindowHandle();

for (String handle : driver.getWindowHandles()) 

{

driver.switchTo().window(handle);

}

Q.28) How can one upload a file in Selenium WebDriver?

The command element.send_keys(file path) is used to upload a file in Selenium Webdriver. But before you that, you must use the html tag: ‘input’ where the attribute type should be ‘file’. Here is an example to understand it better:

<input type="file" name="my_uploaded_file" size="50" class="pole_plik">

element = driver.find_element_by_id(”my_uploaded_file")

element.send_keys("C:myfile.txt")

Q.29) What is the importance of testng.xml?

If you are interviewing for Selenium, you surely know the importance of testing. Selenium does not support the generation of the report as well as test case management. We, therefore, use the TestNG framework with Selenium. It is way advanced compared to Junit, and it is easier to implement annotations making TestNG framework the choice with Selenium Webdriver. 

You can define the test suites and grouping of test classes in TestNG, by taking commands from the testing.xml file. It is represented in an XML file and not in a test suite within the testing source code because the suite is a feature of execution. A test suite is a group or collection of test cases.

The testng.xml file should contain the name of all the methods and classes that you wish to execute as a portion of that execution flow.

Some of the advantages of using testng.xml file are:

  • It lets the execution of multiple test cases from multiple classes
  • It lets the execution of test cases in groups, where a single test can belong to multiple groups.
  • It lets parallel execution.

Q. 30) Explain DataProviders in TestNG. Is it possible to call a single data provider method for multiple functions and classes?

One of the advanced selenium interview questions. DataProvider is a feature of TestNG, enabling developers to write DataDriven tests. It supports DataDriven testing, meaning that the same test method can run multiple times with different data-sets. DataProvider is just a method of passing parameters to the test method.

@DataProvider is a method for providing data for a test method. The annotated method must give back an Object[] where each Object[] can be allocated to the parameter list of the test method.

Yes. It possible to call a single data provider method for multiple functions and classes. The same DataProvider can be used in several functions and classes by declaring DataProvider in a separate class and then using it again in multiple classes.

Q. 31) What are the features of TestNG?

  • Before and after annotations
  • XML based test configuration
  • Multithreaded execution
  • Open API
  • Better reporting
  • Data-Driven testing
  • Dependent Groups.
  • Dependent methods

Learn Online Software Development Courses online from the World’s top Universities. Earn Executive PG Programs, Advanced Certificate Programs or Masters Programs to fast-track your career.

Selenium Test Automation for E-commerce Websites

Objective: Create a Selenium topics test suite to automatically test the key features of an e-commerce website, such as user registration, login, product search, shopping cart, and checkout.

Description: The complexity of e-commerce websites and the possible influence on user experience necessitate thorough testing. Beginners can comprehend the difficulties of testing dynamic web pages, managing numerous user interactions, and validating e-commerce operations by developing a Selenium topics test automation suite.

Selenium Data-Driven Testing

Objective: Use Selenium topics to implement data-driven testing, which involves testing a web application using a variety of test data sets that are kept in databases, CSV files, or other external data sources.

Description: By running test cases with various data inputs, data-driven testing increases the effectiveness of test cases. This project proposal encourages reusability and maintainability by enabling beginners to explore multiple data sources, read and interpret data, and run tests dynamically.

Continuous Integration (CI) Tools and Selenium Integration

Objective: Integrate CircleCI, Travis CI, and Jenkins with Selenium topics test automation to provide automated testing for every code commit.

Description: Contemporary software development methodologies require continuous integration. This project gives novices practical experience using CI tools to automate the test execution process, resulting in quicker feedback and better software quality.

Selenium-based cross-browser testing

Objective: Selenium WebDriver enables the automation of test cases on browsers such as Internet Explorer, Firefox, Chrome, and Safari.

Description: Although they adhere to Open Web Standards, browser companies have their own interpretations of those standards. Thoroughly debugging a website’s source code does not guarantee that the site will appear and function as intended on various browsers (or various versions of a single browser), as they all render HTML, CSS, and JavaScript in different ways. With the aid of this project idea, beginners may manage browser-specific behaviors and effectively address compatibility issues.

Automated Selenium Testing for Mobile Apps

Objective: Create Selenium topics test scripts to automate the testing of mobile applications using either emulation or actual hardware.

Description: This project introduces newcomers to the problems of mobile test automation as the world relies more and more on mobile applications. It entails creating mobile testing environments, dealing with mobile gestures, and examining app functioning across several platforms.

Conclusion

Coming to the end of the Selenium interview questions and answers guide, we hope this helps you get your job. Selenium interview questions for experienced are more technical, but with fierce competition over jobs, it is always great to be prepared well for an interview.

If you are interested in learning Selenium, DevOps and everything about Full Stack development, check out IIIT-B & upGrad’s Executive PG Program in Full Stack Software Development Program.

Frequently Asked Questions (FAQs)

1. Which programming language is best for Selenium?

Selenium is one of the most popular portable open-source frameworks designed for the quality assurance of web-based applications. Generally, Selenese is the language used with Selenium, specific to this testing domain. But Selenium also supports the use of other languages for writing test automation scripts. Out of all others, Java and Python are the most preferred languages used with Selenium. Due to its ease-of-use and simple syntax, Python reduces program execution time with Selenium. Plus, with Python API, connecting to a browser becomes very easy. Java is extremely versatile and popular too, and with Selenium, it offers shorter execution times and efficient error handling.

2. Is Selenium tough to learn?

Selenium is not exactly difficult to learn, but it will take a shorter time to learn it with a properly planned study strategy and discipline. It can be an uphill task when you are learning Selenium entirely by yourself. But when you have the right study roadmap, you can learn the basics of Selenium within a month or so. But before learning Selenium, you need to have an excellent working knowledge of Java or Python and HTML concepts. Selenium with Java or Python is one of the hottest skill sets in demand today. You can find ample resources to learn these technologies and build a lucrative career.

3. What is the difference between QTP and Selenium?

Both Selenium and QTP are popular tools used for automation testing purposes. While QTP is used for automated functional testing of software applications, Selenium is used for the automated testing of web-based applications. QTP is a licensed tool and expensive, too; it comes with its own built-in repository of objects. QTP offers a higher rate of automation compared to Selenium. However, Selenium is an open-source platform and needs no licenses; users do not incur expenses for this tool. And this offers more flexibility in testing than QTP – it supports different programming languages. Selenium testing scripts can execute across different IDEs, unlike QTP.

4. What is the highest salary for Selenium Tester?

The highest salary for a Selenium Tester is 15.0 lakhs per annum.

5. What are the four components of Selenium?

The four components of Selenium are- Selenium IDE Selenium RC Selenium WebDriver Selenium Grid

6. What are the three major components of Selenium?

The three major components of Selenium include- Selenium WebDriver Selenium Testing Selenium Java

7. Which language is best for Selenium?

Java and Python are best for Selenium.

RELATED PROGRAMS