Latest 50 Selenium Interview Questions To Crack Any Interview
Question 1: What is Selenium?
Answer: Selenium is a browser automation tool that lets you automate operations like – type, click, and selection from a drop-down of a web page.
Question 2: How is Selenium different from commercial browser automation tools?
Answer: Selenium is a library that is available in many languages, i.e. Java, C#, python, ruby, PHP, etc. while most commercial tools are limited in their capabilities of being able to use just one language. Moreover, many of those tools have their proprietary language, which is of little use outside the domain of those tools. Most commercial tools focus on record and replay while Selenium emphasis using Selenium IDE (Selenium record and replay) tool ONLY to get acquainted with Selenium working and then move on to more mature Selenium libraries like Remote control (Selenium 1.0) and Web Driver (Selenium 2.0).
Though most commercial tools have built-in capabilities of test reporting, error recovery mechanisms and Selenium does not provide any such features by default. But given the rich set of languages available with Selenium, it very easy to emulate such features.
Read Also: Mindtree Java Selenium Questions
Question3: What are the set of tools available with Selenium?
Answer: Selenium has four sets of tools – Selenium IDE, Selenium 1.0 (Selenium RC), Selenium 2.0 (WebDriver), and Selenium Grid. Selenium Core is another tool, but since it is available as part of Selenium IDE as well as Selenium 1.0, it is not used in isolation.
Question 4: Which Selenium Tool should I use?
Answer: It entirely boils down to where you stand today in terms of using Selenium. If you are altogether new to Selenium, then you should begin with Selenium IDE to learn Selenium location strategies and then move to Selenium 2 as it is the most stable Selenium library and future of Selenium. Use Selenium Grid when you want to distribute your test across multiple devices. If you are already using Selenium 1.0 than you should begin to migrate your test scripts to Selenium 2.0
Question5: What is Selenium IDE?
Answer: Selenium IDE is a Firefox plug-in, which is (by and large) used to record and replay test is Firefox browser. Selenium IDE can be used only with the Firefox browser.
Question 6: Which language is used in Selenium IDE?
Answer: Selenium IDE uses HTML sort of language called Selenese. Though other languages (java, c#, PHP, etc.) cannot be used with Selenium IDE, Selenium IDE lets you convert test in these languages so that they could be used with Selenium 1.0 or Selenium 2.0
Question 7: What is Selenium 1.0?
Answer: Selenium 1.0 or Selenium Remote Control (popularly known as Selenium RC) is the library available in a wide variety of languages. The primary reason for the advent of Selenium RC was the incapability of Selenium IDE to execute tests in the browser other than Selenium IDE and the programmatical limitations of language Selenese used in Selenium IDE.
Check Also: Automation Interview Questions
Question 8: What is Selenium 2.0?
Answer: Selenium 2.0, also known as WebDriver, is the latest offering of Selenium. It provides
- better API than Selenium 1.0
- supports more UI complicated UI operations like drag and drop
Question 9: What are the element locators available with Selenium, which could be used to locate elements on the webpage?
Answer: There are mainly 4 locators used with Selenium –
- HTML id
- HTML name
- XPath locator and
- CSS locators
Question 10: What is Selenium Grid?
Answer: Selenium grid lets you distribute your tests on multiple machines and all of them at the same time. Hence you can execute tests on IE on Windows and Safari on Mac machine using the same test script (well, almost always). This greatly helps in reducing the time of test execution and provides quick feedback to stack holders.
Selenium IDE Questions
Question 11: What are two modes of views in Selenium IDE?
Answer: Selenium IDE can be opened either in sidebar (View > Sidebar > Selenium IDE) or as a pop up window (Tools > Selenium IDE). While using Selenium IDE in the browser sidebar, it cannot record user operations in a popup window opened by the application.
Question 12: Can I control the speed and pause test execution in Selenium IDE?
Answer: Selenium IDE provides a slider with Slow and Fast pointers to control the speed of execution.
Question 13: Where do I see the results of Test Execution in Selenium IDE?
Answer: Result of test execution can be viewed in a log window in Selenium IDE –
Question 14: Where do I see the description of commands used in Selenium IDE?
Answer: Commands of description can be seen in Reference section –
Question 15: Can I build a test suite using Selenium IDE?
Answer: Yes, you can first record individual test cases and then group all of them in a test suite. Following this entire test suite could be executed instead of executing individual tests.
Question 16: What verification points are available with Selenium?
Answer: There are largely three types of verification points available with Selenium –
- Check for the page title
- Check for certain text
- Check for the certain element (text box, drop-down, table, etc.)
Question 17: I see two types of check with Selenium – verification and assertion, what’s the difference between tow?
Answer: · A verification check lets test execution continue even in the wake of failure with the check, while assertion stops the test execution. Consider an example of checking the text on the page, and you may like to use the verification point and let test execution continue even if the text is not present. But for a login page, you would like to add an assertion for the presence of text box login as it does not make sense continuing with test execution if the login text box is not present.
Question 18: I don’t see checkpoints added to my tests while using Selenium IDEL, how do I get them added to my tests?
Answer: You need to use the context menu to add checkpoints to your Selenium IDE tests –
Question 19: How do I edit tests in Selenium IDE?
Answer: There are two ways to edit tests in Selenium IDE; one is the table view while others looking into the source code of recorded commands –
Question 20: What is the syntax of the command used in Selenium?
Answer: There are three entities associated with a command –
- Name of Command
- Element Locator (also known as Target)
- Value (required when using echo, wait, etc.)
Question 21: There are tons of Selenium Command, am I going to use all of them
Answer: This entirely boils down to operations you are carrying out with Selenium. Though you would be using following Selenium Commands more often –
- Open: opens a web page.
- Click/clickAndWait: click on an element and waits for a new page to load.
- Select: Selects a value from a drop down value.
- verifyTitle/assertTitle: verifies/asserts page title.
- verify/assert ElementPresent: verifies/asserts presence of element, in the page.
- verify/assert TextPresent verifies/asserts expected text is somewhere on the page.
Question 22: How do I use HTML id and name while using Selenium IDE
Answer: Html id and name can be used as it is in selenium IDE. For example, the Google search box has a name – “q” and id – “list-b,” and they can be used as a target in Selenium IDE –
Question 23: What is XPath? When would I have to use XPath in Selenium IDE?
Answer: XPath is a way to navigate in the xml document, and this can be used to identify elements on a web page. You may have to use XPath when there is no name/id associated with the element on the page, or only a partial part of name/ide is constant.
- Direct child is denoted with – /
- Relative child is denoted with – //
- Id, class, names can also be used with XPath –
- · //input[@name=’q’]
- · //input[@id=’lst-ib’]
- · //input[@class=’ lst’]
If only part of id/name/class is constant than “contains” can be used as –
- · //input[contains(@id,’lst-ib’)]
Question 24: What is CSS location strategy in Selenium?
Answer: CSS location strategy can be used with Selenium to locate elements, it works using cascade style sheet location methods in which –
The direct child is denoted with – (space)
A relative child is denoted with – >
Id, class, names can also be used with XPath –
- · css=input[name=’q’]
- · css=input[id=’lst-ib’] or input#lst-ib
- · css=input[class=’ lst’] or
If only part of id/name/class is constant than “contains” can be used as –
- · css=input[id*=’ lst-ib ‘)]
Element location strategy using inner text
- · CSS = a:contains(‘log out’)
Question 25: There is an id, name, XPath, CSS locator, which one should I use?
Answer: If there are constant name/id available, then they should be used instead of XPath and CSS locators. If not, then CSS locators should be given preference as their evaluation is faster than XPath in most modern browsers.
Question 26: I want to generate random numbers, dates as my test data, how do I do this in Selenium IDE?
And for a date –
Question 27: Can I store the result of an evaluation and use it later in my test?
Answer: You can use the “store” command to achieve this. You can save the result of an evaluation in a variable and use it later in your Selenium IDE script. For example, we can store a value from a text box as following, and later use it to type it in another text box –
Question 28: I have stored the result of an evaluation; can I print it in IDE to check its value?
Answer: You can use echo command as following to check the stored value in Selenium IDE – storeText
Answer: You could use verify/assertAlert to check the presence of alert on the page. Since selenium cannot click on the “Ok” button on the js alert window, the alert itself does not appear on the page when this check is carried out.
Question 30: Selenium has recorded my test using XPath. How do I change them to CSS locators?
Answer: You can use drop-down available next to Find in Selenium to change element locator used by Selenium –
Question 31: I have written my element locator, how do I test it?
Answer: You can use the Find button of Selenium IDE to test your locator. Once you click on it, you would see the element is highlighted on the screen provided your element locator is right Else one error message would be displayed in the log window.
Question 32: I have written one js extension; can I plug it in Selenium and use it?
Answer: You could specify the js extension in the “Options” window of Selenium IDE.
Question 33: How do I convert my Selenium IDE tests from Selenese to another language?
Answer: You could use the Format option of Selenium IDE to convert tests in another programming language –
Question 34: I have converted my Selenium IDE tests to java, but I am not able to execute them, execution options, as well as Table tab of Selenium IDE, is disabled.
Answer: This is because Selenium IDE does not support the execution of the test in any other language than Selenese ( the language of Selenium IDE). You can convert Selenium IDE in a language of your choice and then use Selenium 1.0 to execute these tests in that language.
Question 35: I want to use only Selenese as my test script language but still want to execute tests in other browsers, how do I do that?
Answer: You can execute you Selenese test in another browser by specifying the “-htmlSuite” followed by the path of your Selenese suite while starting the Selenium Server. Selenium Server would be covered in detail in question about Selenium RC.
Question 36: I have added one command in the middle of the list of commands, how do I test only this new command?
Answer: You can double click on the newly added command, and Selenium IDE would execute only that command in the browser.
Question 37: Can I make Selenium IDE tests begin test execution from a certain command and not from the very first command?
Answer: You could set a command as a “start” command from the context menu. When a command is set as the start command, then a small green symbol appears before the command. The Same context menu can be used to toggle this option.
Question 38: Are there other tools available outside Selenium IDE to help me tests my element locators
Answer: You could XPath checker – to test you XPath locators and Firefinder (a Firebug add-on) to test you CSS locators –
Firefinder can also be used to test XPath locators.
Question 39: What is an upcoming advancement in Selenium IDE?
Answer: The latest advancement in Selenium IDE would be to have capabilities of converting Selenium IDE tests in Webdriver (Selenium 2.0) options. This would help to generate quick and dirty tests for Selenium 2.0
Question 40: How can I use a looping option (flow control) is Selenium IDE
Answer: Selenese does not provide support for looping, but there is an extension that could be used to achieve the same.
This extension can be added under the “Selenium IDE Extension” section to use the loop feature in Selenium IDE.
Question 41: Can I use a screen coordinate while using click command? I want to click on the specific part of my element.
Answer: You would need to use the clickAT command to achieve. the clickAt command accepts element locator and x, y coordinates as arguments – clickAt(locator, coordString)
Question 42: How do I verify the presence of drop-down options using Selenium?
Answer: Use assertSelectOptions as following to check options in a drop-down list –assertSelectOptions
Question 43: Can I get data from a specific HTML table cell using Selenium IDE?
Answer: Use the storeTable command to get data from a specific cell in an HTML table, following example store text from cell 0,4 from an HTML table –
Question 44: I want to make Selenium IDE record and display CSS locator followed by other locators, is it possible to give high priority to CSS locator in Selenium IDE?
Answer: You can change the default behavior of Selenium IDE > element locator preference by creating js file with following–
= [‘css:name’, ‘CSS:id’, ‘id’, ‘link’, ‘name’, ‘XPath:attributes’];
And add this file under “Selenium IDE Extension” under Selenium Options.
Question 45: My application has dynamic alerts which don’t always appear, how do I handle them?
Answer: If you want to simulate clicking “ok “ on alert than use – chooseOkOnNextConfirmation and if you want to simulate clicking “cancel” on alert than use – chooseCancelOnNextConfirmation ( )
Question 46: Can I right-click on a locator?
Answer: You can use the command – contextMenu ( locator) to simulate a right-click on an element on a web page.
Question 47: How do I capture a screenshot of the page using Selenium IDE?
Answer: Use command – captureEntirePageScreenshot to take a screenshot of the page.
Question 48: I want to pause my test execution after the certain command.
Answer: Use pause command which takes time in milliseconds and would pause test execution for a specified time – pause ( waitTime )
Question 49: I used the open command to launch my page, but I encountered a timeout error.
Answer: This happens because open commands wait for only 30 seconds for a page to load. If your application takes more than 30 sec, then you can use “setTimeout ( timeout )” to make selenium IDE wait for the specified time before proceeding with test execution.
Question 50: What’s the difference between type and typeKeys commands?
Answer: type command simulates enter operations at one go while typeKeys simulates keystroke key by key.
typeKeys could be used when typing data in a text box that brings options (like Google suggestion list) because such operation is not usually simulated using type command.