Most Asked Selenium Interview Questions & Answers
During recent times we have heard lots of news about layoffs from big companies, and many employees started looking for jobs. The first thing we should do during this time is to prepare for an interview and acquire knowledge on trending topics.
Today’s post is for all the job seekers who are going through the job hunting phase. In the current job market in almost all QA, Automation or SDET job profiles you can definitely expect questions from Selenium, that’s why we have decided to create a post on the most asked Selenium Interview questions and answers.
Before we start looking into the interview questions and answers let’s understand quickly about Selenium along with the reasons behind the popularity of the same.
The most important fact about Selenium is that it has the highest market share in any of the automation solutions available in the market for web automation, and with that fact let’s start our interview preparation with Selenium questions and answers.
What is Selenium?
Selenium is an open source umbrella project for a range of tools and libraries aimed at supporting browser automation. It provides a playback tool for authoring functional tests across most modern web browsers, without the need to learn a test scripting language. In simple words it provided an automation solution, by using it we can write test scripts for Web Automation and perform action on webelements.
Why do we need Selenium?
In most organisations, it is the job of quality analyst (QA) engineers to test web applications by using Selenium. They are required to write scripts that can help in maximising accuracy and test coverage to make changes in the project and maintain the infrastructure of the test.
Interview Questions and Answers
- How to perform back, forward and refresh action in Selenium?
Ans: navigate() can be used for these actions.
- What is the return type of findelements?
Ans: List of elements with similar property
- What will happen if no webelement is found for findelements?
Ans : It will return an empty list
- What will happen if no webelement is found for findelement?
Ans: It will give error as :NoSuchElementException
- How to select value from dropdown in Selenium?
Ans: Using select class as below
Select technology = new Select(driver.findElement(By.xpath(“//select[@id=’effectTypes’]”)));
- What are the methods provided in Selenium to select from dropdown?
Ans: Select class can be used for dropdown, below are the methods provided by Select class
- How to fetch text from UI in Selenium?
Ans: Text can be fetch by below two ways:
- How to get current url, title and page source?
- How to clear text using Selenium?
Ans: clear() — method is used to clear text from the text area
- How to do Browser Initialization for all types of browser?
Firefox ⇒ WebDriver driver = new FirefoxDriver();
Chrome ⇒ WebDriver driver = new ChromeDriver();
Internet Explorer ⇒ WebDriver driver = new InternetExplorerDriver();
Safari Driver ⇒ WebDriver driver = new SafariDriver();
- What are the types of locators used to identify objects?
Ans: Below is the list of locators used to identify objects:
- Class Name
- Tag Name
- Link Text & Partial Link Text
- Link Text
- CSS Selector
- DOM (Document Object Model)
- Difference between getwindowHandle and getwindowHandles ?
driver.getWindowHandle() returns a String of alphanumeric window handle and is mainly used to get the window handle of the current window.
driver.getWindowHandles() returns a set of window handles and is mainly used to get the window handle of all the current windows.
- How to handle popups and alerts in Selenium?
Ans: To handle pop up Alert can be used:
Alert alert = driver.switchTo().alert();
alert.accept(); //it will click on “ok”
alert.dismiss(); //it will click on “cancel”
- How to handle mouse and keyboard events using Selenium?
Keyboard Events Using Selenium Actions Class:
- sendKeys(keysToSend) : sends a series of keystrokes
- keyDown(theKey) : Sends a key press without releasing it. (example: Keys.ALT, Keys.SHIFT, or Keys.CONTROL)
- keyUp(theKey): Performs a key release
Mouse Events Using Selenium Actions Class:
- click (): click on element
- doubleClick (): Double clicks on Element
- contextClick() : Performs a context-click (right click)
- clickAndHold(): Clicks at the present mouse location
- dragAndDrop(source, target): Invokes click-and-hold at the source location and moves to the location of the target element before releasing the mouse. source – element to grab, target – element to release
- dragAndDropBy(source, xOffset, yOffset) : Performs click-and-hold at the source location, shifts by a given offset, then frees the mouse. xOffset – to shift horizontally, yOffset – to shift vertically
- moveByOffset(x-offset, y-offset): Shifts the mouse from its current position (or 0,0) by the given offset. x-offset – Sets the horizontal offset (negative value – shifting the mouse to the left), y-offset – Sets the vertical offset (negative value – shifting the mouse to the up)
- moveToElement(toElement): It shifts the mouse to the centre of the element
- release(): Releases the depressed left mouse button at the existing mouse location
- What are the functions most commonly used in xpath, describe any 5?
- And OR
- Starts with
- XPath Axes
Hope the shared list of questions and answers will help the job seekers to get their dream job. One important point to remember is that there are also tools which are giving tough competition to Selenium and some of the most used automation solutions after Selenium are Cypress, Playwright and Puppeteer.
If you are looking for jobs related to Automation, QA or SDET roles then do checkout jobs with high salary at https://talent500.co/ .