Selenium WebDriver Interview Questions
In this section, we will be sharing the most commonly Selenium WebDriver Interview Questions for Selenium WebDriver. You are going to any year’s experience profile, revise questions. For more Interview questions, You Can Visit Our SoftwareTestingo Regularly.
The difference between absolute path & Relative path
Absolute path starts from “HTML” example “html/body/div[5]/div[2]/div/” Relative path is in reference to example “By.xpath(“//table[@id=’name’]”
Scenario: There is a building let’s generate its path:
Tell me some TestNG Annotations
- @BeforeSuite
- @AfterSuite
- @BeforeTest
- @AfterTest
- @BeforeGroups
- @AfterGroups
- @BeforeClass
- @AfterClass
- @BeforeMethod
- @AfterMethod
What are the Desired capabilities
Desired Capability is a series of key/value pairs that encapsulate aspects of a browser means we can set the behavior of the browser on the runtime. The Desired Capabilities help to set properties for the WebDriver. A typical use case will be to set the path for the FireFoxDriver if our local installation doesn’t correspond to the default settings.
The difference between Selenium RC and Selenium Web driver
- Selenium RC is an old version of Selenium Web Driver
- In Selenium RC, we need to start the server, and it acts as communication between Selenium RC and browser. The server injects code into the browser and executes automation.
- In the case of WebDriver, it communicates directly with Selenium RC
- Also simple language we can selenium Webdriver supported for Java Object Orient Programming.
What is Automation Framework
The framework is a process that will make automation develop and maintain a team. The framework includes what would be folder structure, Common function library, how would be storing and fetching test data, how would be storing the result, how continuous integration will be performed, etc
What is the difference between a driver.Close() and driver.Quit () method?
- Driver.close(): will close the browser which is in focus of web driver object
- Driver.quit(): will close all the browsers and closes the session
How can we get the font size, font color, font type used for a particular text on a web page using Selenium web driver
- System.out.println(“WebElement Font Size is : “+ driver.findElement(By.id(“submitbox”)).getCssValue(“font-size”));
- System.out.println(“WebElement Font Color is : “+driver.findElement(By.id(“submitbox”)).getCssValue(“font-color”));
- System.out.println(“WebElement Font Background Color is : “+driver.findElement(By.id(“submitbox”)).getCssValue(“background-color”));
How to Run Tests in Multiple Browser Parallel
Selenium-Grid allows you to run your tests on different machines against different browsers in parallel
What is Selenium 2.0
- Selenium 1.0: Selenium RC
- Selenium 2.0: Selenium WebDriver
How will you find an element using Selenium
- By ClassName
- By CssSelector
- By ID
- By LinkText
- By Name
- By TagName
- By XPath
Mention what is the use of X-path
We can interact with the Website with properties ID, CLASSNAME, NAME, etc. XPath is another way to navigate through elements and attributes in an XML document. As per W3C:
- XPath is a syntax for defining parts of an XML document
- XPath uses path expressions to navigate in XML documents
- XPath contains a library of standard functions
- XPath is a major element in XSLT
- XPath is a W3C recommendation
Technical Challenges with Selenium
- Selenium supports only web-based applications
- It doesn’t support any non-web based (Java Applet, Java Swing, .Net Client Server, etc.) applications
- Since Selenium is a free tool, there is no direct support available
- Bitmap comparison not supported by Selenium
- No direct reporting, logging, test data handling feature available
- Need to learn a language for scripting with selenium
- Sometimes pages take more time to load when working with Selenium.
- For uploading and downloading file no separate feature present, sometimes need to take help of window automation tools like AutoIT.
- No built-in repository available, have to use .properties file or other feature to create object repository
What are the Advantages of Selenium
- Supports multiple browsers
- Provides the option of using the full range of IDEs such as Eclipse, Netbeans, etc
- Supports multiple languages JAVA, NET, Ruby, etc
- Extensive Selenium community
- Selenium is open-source. Most open-source tools help other open-source tools
- Selenium supports Continuous Integration
- Various options to find an element on a website
- Same developed scripts run on multiple browsers
Mention what the Difference between Implicit wait and Explicit wait is?
We tell the web driver to wait for specific time suppose 10seconds before any web element Implicit wait: be visible on the website. The implicit wait is applied to all elements present after declaring once.
- Implicit wait: is applied to all elements present after declaring once. If an element is visible in 2 seconds, that web driver won’t wait for the next 8 seconds.
- Explicit wait: wait is applied for a specific element, not all elements. In Explicit wait, we tell the web driver to wait for this particular element until any condition is fulfilled. For example, wait for the submit button for 10 seconds until the element becomes clickable.
Explain what is the Difference between find element() and find elements()
- findElement() will return only single WebElement, and if that element is not located or we use some wrong selector, then it will throw NoSuchElement exception. If multiple elements are present with the same selector, then it will give the first element.
- findElements() will return List of WebElements – for this, and we need to provide a locator in such a way that it can find multiple elements
Explain what is Data-driven framework and Keyword driven
- Data-driven framework: In this test are created, verified, and executed based on test data stored in some database, either Excel, SQL, etc. In the simplest form, the tester supplies the inputs from a row in the table and expects the outputs which occur in the same row.
- Keyword-driven framework: Also known as table-driven testing or action word based testing. This method separates the documentation of test cases -including the data to use- from the prescription of the way the test cases are executed. As a result, it separates the test creation process into two distinct stages: a design and development stage, and an execution stage.
What is Object Repository
Object Repository is the location where we can store information/properties of our elements, and scripts identify the features from Object Repository to identify them.
How do you verify if the Checkbox/Radio is checked or not
driver.findElement(By.id(“submitbutton”)).getAttribute(“checked”)
How do you launch IE/chrome browser
You need to download the executable file for chrome/IE and run commands
System.setProperty(“webdriver.chrome.driver”, “path to executable file”); WebDriver driver = new ChromeDriver();
How do you upload a file
We can use the Selenium “sendKeys” function if it didn’t work then we need to use the help of Windows Automation Tools like Auto IT
How do you get the current page URL
driver.getCurrentURL();
How to get a typed text from a textbox
driver.findElement(By.id(“submitbutton”)).getAttribute(“text”);
or
driver.findElement(By.id(“submitbutton”)).getText();
What are the prerequisites to run selenium web driver
Knowledge of Java and any other supported Programming language
What is Selenium Grid
Selenium Grid allows you to run your tests on different machines against different browsers in parallel. That is, running multiple tests at the same time against different machines running different browsers and operating systems
How to get the title of the page
driver.getTitle();
FirefoxDriver is a class or an interface
Class
How do you handle https website in selenium
FirefoxProfile myProfile = allProfiles.getProfile(“CertificateIssue”); myProfile.setAcceptUntrustedCertificates(true);
HtmlUnitDriver
HTML unit driver is the lightest weight and fastest implementation headless browser for WebDriver
What are the benefits of using TestNG
- It generates logs.
- You can do parallel testing.
- Annotations help to set program/function priority easy.
- Allow generating an HTML report of execution.
- You can group test cases.
- You can set test case priorities.
- You can do data Parameterization.
What is the use of AutoIt tool
AutoIt v3 is a freeware BASIC-like scripting language designed for automating the Windows GUI and general scripting.
How to perform double click using WebDriver
Actions action = new Actions(driver); WebElement element = driver.FindElement(By.id(“submit”)); action.DoubleClick(element).Build().Perform();
What is the difference b/w getWindowHandles() and getWindowHandle()
- getWindowHandles()- is used to get the address of all the open browser, and its return type is Iterator<String>.
- getWindowHandle()- is used to get the address of the current browser where the control is, and return type is String.
What are the limitations of Selenium IDE
Selenium IDE is a record, and play tool can only support Mozilla browser
How will you handle dynamic elements
We use Relative XPath
Which one is better XPath or CSS
CSS Locator has better performance than the XPath Locator
What is the actions class in WebDriver
The user-facing API for emulating complex user gestures. Use this class rather than using the Keyboard or Mouse directly.
Most Searched Words: Selenium WebDriver Interview Questions for Freshers, WebDriver Interview Questions For Experience, Top WebDriver Interview Questions, Highly asked WebDriver Interview Questions, common WebDriver Interview Questions recently asked WebDriver Interview Questions
Tricky Selenium Webdriver Automation Testing Interview Questions Asked in Interview: We have published so many posts regarding interview questions, but we thought we should publish one such post where we can gather all most questions asked in an interview, Java selenium tricky interview questions, selenium webdriver testing interview questions and selenium interview questions for experienced.
In the below questions, we try to cover Java, Selenium webdriver, SQL, Manual testing, and other tools which are using by testers.
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.
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.
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
- does not suffer from javascript security restriction which Selenium 1.0 does
- 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 input.lst
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?
Answer: This can be achieved by executing javascript in Selenium. Javascript can be executed using the following syntax – type
- css=input#s
- javascript{Math.random()}
And for a date –
- type
- css=input#s
- javascript{new 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 –
- storeText
- css=input#s
- var1
- type
- css=input#d
- ${var1}
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
- css=input#s
- var1
- echo
- ${var1}
Question 29: Can I handle a javascript alert using Selenium?
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 – https://addons.mozilla.org/en-US… to test you XPath locators and Firefinder (a Firebug add-on) to test you CSS locators – https://addons.mozilla.org/en-US…
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 –
- storeTable
- css=#tableId.0.4
- textFromCell
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–
LocatorBuilders.order = [‘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.
Leave a Reply