Selenium Interview Questions and Answers
Question - 41 : - How will you use Selenium to upload a file ?
Answer - 41 : -
You can use “type”command to type in a file input box of upload file. Then, you have to use “Robot” class in JAVA to make file upload work.
Question - 42 : - Which web driver implementation is fastest?
Answer - 42 : -
HTMLUnit Driver implementation is fastest, HTMLUnitDriver does not execute tests on browser but plain http request, which is far quick than launching a browser and executing tests
Question - 43 : - Explain how you can handle frames using Selenium 2.0 ?
Answer - 43 : -
To bring control on HTML frame you can use “SwitchTo” frame method-
driver.switchTo().frame(“frameName”);
To specify a frame you can use index number
driver.switchTo().frame(“parentFrame.4.frameName”);
This would bring control on frame named- “frameName” of the 4th sub frame names “parentFrame”
Question - 44 : - What is the difference between getWindowhandles() and getwindowhandle() ?
Answer - 44 : -
getwindowhandles(): It is used to get the address of all the open browser and its return type is Set
getwindowhandle(): It is used to get the address of the current browser where the control is and return type is string
Question - 45 : - Explain how you can switch back from a frame?
Answer - 45 : -
To switch back from a frame use method defaultContent()
Syntax-driver.switchTo().defaultContent();
Question - 46 : - List out different types of locators?
Answer - 46 : -
Different types of locators are
- By.id()
- By.name()
- By.tagName()
- By.className()
- By.linkText()
- By.partialLinkText()
- By.xpath
- By.cssSelector()
Question - 47 : - What is the command that is used in order to display the values of a variable into the output console or log?
Answer - 47 : -
In order to display a constant string, command can be used is echo
If order to display the value of a variable you can use command like echo ${variable name>>
Above is using PHP. If you are using Java, replace echo with System.out.println
Question - 48 : - Explain how you can use recovery scenario with Selenium?
Answer - 48 : -
Recovery scenarios depends upon the programming language you use. If you are using Java then you can use exception handling to overcome same. By using “Try Catch Block” within your Selenium WebDriver Java tests
Question - 49 : - Explain how to iterate through options in test script?
Answer - 49 : -
To iterate through options in test script you can loop features of the programming language, for example to type different test data in a text box you can use “for” loop in Java
// test data collection in an array
String[ ] testData = { “test1” , “test2” , “test3” } ;
// iterate through each test data
For (string s: test data) { selenium.type ( “elementLocator”, testData) ; }
Question - 50 : - How can you prepare customized html report using TestNG in hybrid framework ?
Answer - 50 : -
There are three ways
- Junit: With the help of ANT
- TestNG: Using inbuilt default.html to get the HTML report. Also XST reports from ANT, Selenium, Testng combinations
- Using our own customized reports using XSL jar for converting XML content to HTML