Selenium Interview Questions

 1.    What is Selenium?

Selenium is a suite of tools for browser automation. It is composed of "IDE", a recording and playback mechanism, "WebDriver" and "RC" which provide APIs for browser automation in a wide variety of languages, and "Grid", which allows many tests using the APIs to be run in parallel. It works with most browsers, including Firefox from 3.0 up to 7, Internet Explorer 8, Google Chrome, Safari and Opera 11.5

2.    What test can Selenium do?
Selenium could be used for the functional, regression, load testing of the web based applications. The automation tool could be implemented for post release validation with continuous integration tools like Jenkins, Hudson, QuickBuild or CruiseControl.

3.    What is the price of Selenium license per server?
Selenium is open source software, released under the Apache 2.0 license and can be downloaded and used without charge.

4.    How much does Selenium license cost per client machine?
Selenium is open source software, released under the Apache 2.0 license and can be downloaded and used without charge.

5.    Where to download Selenium?
Selenium can be downloaded and installed for free from seleniumhq.org

6.    What is the latest version of Selenium?
The latest versions are Selenium IDE 1.3.0, Selenium Server (formerly the Selenium RC Server) 2.8.0, Selenium Client Drivers Java 2.8.0, Selenium Client Drivers C# 2.8.0, Selenium Client Drivers Ruby 2.8.0, Selenium Client Drivers Python 2.8.1, Selenium Grid 1.0.8.


8.    What is Selenium IDE?
Selenium IDE is a Firefox add-on that records clicks, typing, and other actions to make a test cases, which QA Tester can play back in the Firefox browser or export to Selenium RC. Selenium IDE has the following features: record/play feature, debugging with step-by-step and breakpoints, page abstraction functionality, an extensibility capability allowing the use of add-ons or user extensions that expand the functionality of Selenium IDE
9.    What are the limitations of Selenium IDE?
Selenium IDE has many great features and is a fruitful and well-organized test automation tool for developing test cases, in the same time Selenium IDE is missing certain vital features of a testing tool: conditional statements, loops, logging functionality, exception handling, reporting functionality, database testing, re-execution of failed tests and screenshots taking capability. Selenium IDE doesn't for IE, Safari and Opera browsers.

10.    What does SIDE stand for?
Selenium IDE. It was a very tricky interview question.

11.    What is Selenium Remote Control (RC) tool?
Selenium Remote Control (RC) is the powerful solution for test cases that need more than simple browser actions and linear execution. Selenium-RC allows the developing of complex test scenarios like reading and writing files, querying a database, and emailing test reports. These tasks can be achieved by tweaking test cases in your preferred programming language.

13.    What is Selenium Grid?
Selenium Grid extends Selenium RC to distribute your tests across multiple servers, saving you time by running tests in parallel.

14.    What is Selenium WebDriver?
Selenium WebDriver is a tool for writing automated tests of websites. It is an API name and aims to mimic the behaviour of a real user, and as such interacts with the HTML of the application. Selenium WebDriver is the successor of Selenium Remote Control which has been officially deprecated.

15.    How many browsers are supported by Selenium IDE?
Test Engineer can record and playback test with Selenium IDE in Firefox.

16.    Can Selenium test an application on iPhone's Mobile Safari browser?
Selenium should be able to handle Mobile Safari browser. There is experimental Selenium IPhone Driver for running tests on Mobile Safari on the iPhone, iPad and iPod Touch.

17.    Can Selenium test an application on Android browser?
Selenium should be able to handle Android browser. There is experimental Selenium Android Driver for running tests in Android browser.

18.    What are the disadvantages of using Selenium as testing tool?
Selenium weak points are tricky setup; dreary errors diagnosis; tests only web applications

19.    How many browsers are supported by Selenium Remote Control?
QA Engineer can use Firefox 7, IE 8, Safari 5 and Opera 11.5 browsers to run actuall tests in Selenium RC.

20.    How many programming languages can you use in Selenium RC?
Several programming languages are supported by Selenium Remote Control - C# Java Perl PHP Python Ruby

21.  Difference between Absolute path & Relative path.
Absolute path will start with root path (/) and Relative path will from current path (//)
Absolute xPath : /html/body/div[3]/div[2]/div[2]/div[2]/div[2]/div[2]/div[2]/div/div[4]/div[1]/div/div[@id='main']/div[@id='Blog1']/div[1]/div[1]/div/div[1]/div/h3/a
Relative xPath : //h3/a[text()='Working on New Window']

22.  Tell me some TestNG Annotations.
@Test,@Parameters,@Listeners,@BeforeSuite,@AfterSuite,@BeforeTest,@AfterTest,
@DataProvider,@BeforeGroups,@AfterGroups,@BeforeClass,@AfterClass,
@BeforeMethod,@AfterMethod,@Factory
http://testng.org/doc/documentation-main.html#annotations

23.  What are desiredcapabilities?
Desired Capabilities help to set properties for the Web Driver. A typical use case would be to
set the path for the Firefox Driver if your local installation doesn't correspond to the default
settings.
https://code.google.com/p/selenium/wiki/DesiredCapabilities


24.  Difference between Web driver listener and  TestNG Listener.
TestNG and Web driver Listener have different interfaces to implement and call them. They both
modify respective behaviour. You can use Listeners in Annotation. Below 2 URL gives the
 detailed  list of listener and their interfaces.

25.  Which is the best way to locate an element?

Finding elements by ID is usually going to be the fastest option, because at its root, it eventually calls down to document.getElementById(), which is optimized by many browsers.

Finding elements by XPath is useful for finding elements using very complex selectors, and is the most flexible selection strategy, but it has the potential to be very slow, particularly in IE. In IE 6, 7, or 8, finding by XPath can be an order of magnitude slower than doing the same in Firefox. IE provides no native XPath-over-HTML solution, so the project must use a JavaScript XPath implementation, and the JavaScript engine in legacy versions of IE really is that much slower.

If you have a need to find an element using a complex selector, I usually recommend using CSS Selectors, if possible. It's not quite as flexible as XPath, but will cover many of the same cases, without exhibiting the extreme performance penalty on IE that XPath can.

26.  Why we refer Firefox driver to the web driver inheritance.

web Driver driver = new FireFoxDriver();
WebDriver is an interface which contain several abstract methods such as get(...), findElamentBy(...) etc.
We simply create reference of web Driver and we can assign objects (Firefox driver, CromeDriver, IEDriver, Andriod driver etc) to it.
Ex :
WebDriver driver = new FireFoxDriver();-----------(1)
If we are using (1) we can do the same thing by using
FireFoxDriver driver = new FireFoxDriver();---------(2)
We can use (1) and (2) for same purpose but if we want to switch to another browser in same program
then again we have to create the object of other class as for example
CromeDriver driver = new CromeDriver();.
creating object of several class is not good. So we create the reference of WebDriver and
we assign the objects of another class as for example
WebDriver driver; // it is created only one time in the program
driver = new FireFoxDriver();// any where in the program
driver = new CromeDriver(); // any where in the program

27.  What are the features of TestNG?
TestNG is a testing framework designed to simplify a broad range of testing needs, from unit testing (testing a class in isolation of the others) to integration testing (testing entire  systems made of several classes, several packages and even several external frameworks,  such as application servers). You can use test suite,annotations, automatically generation  of report and much more.

28.   What is the difference between thread.Sleep()  and selenium. Set Speed ("2000")?
selenium.setSpeed
 1. Takes a single argument in string format
 Ex: selenium.setSpeed("2000") - will wait for 2 seconds
 2. Runs each command in after setSpeed delay by the number of milliseconds mentioned in set Speed.
 thread.sleep
 1. Takes a single argument in integer format
 ex: thread. Sleep(2000) - will wait for 2 seconds

 2. Waits for only once at the command given at sleep.

29.   In what situation selenium finding element get fails?
·         Element loading issue
·         Dynamic id of web element

30.   What is the difference between "GET" and "NAVIGATE" to open a web page in selenium
web driver?
Get method will get a page to load or get page source or get text that's all whereas navigate  will guide  through the history like refresh, back, forward.For example if we want to move forward and do some functionality and back to the home page this can be achieved  through navigate() only. driver.get will wait  till the whole page gets loaded and driver.navigate  will just redirect to that page and will not wait
3
 1.   Please tell me the difference b/w implicitly  Wait and Explicit wait.

Implicit Wait sets internally a timeout that will be used for all consecutive Web Element searches. It will try lookup the element again and again for the specified amount of time before throwing a NoSuchElementException if the element could not have been found. It does only this and can't be forced into anything else - it waits for elements to show up.


Explicit Wait or just Wait is a one-timer used by you for a particular search. It is more extendible in the means that you can set it up to wait for any condition you might like. Usually, you can use some of the prebuilt Expected Conditions to wait for elements to become clickable, visible, invisible, etc., or just write your own condition that suits your needs.

32.   How we can retrieve the dynamically changing Ids? When we login Facebook the login label's id  changes dynamically thus resulting in failure.
We have a hierarchy of locators and Facebook Is dynamic in nature,so we are not able to use "id" for  identification for after that we have remaining 7 locator's for that :2. xpath ().. 3. name..4. css.. 5. link text.. 6. partiallinktext...7.tag name. so u can use any one for   identifying it. Most probably u can use "xpath" or  "css-locator" and if there r tag then  link text or partial-link text. it depend on u . But we never use id's in Ajax application  because it’s not possible.

33.What is the difference between driver.Close()  and driver.Quit () method?
Close() - It is used to close the browser or page currently which is having the focus.
Quit() - It is used to shut down the web driver instance or destroy the web driver instance
(Close all the windows)

34.   How to scroll web element?--not browser—
FirefoxProfile profile=new FirefoxProfile();
profile.setEnableNativeEvents(true);
WebDriver driver=new FirefoxDriver(profile);
driver.navigate("http://jqueryui.com/draggable/");
Thread.sleep(6000L);
WebElement element=driver.findElement(By.xpath("//div[@id='draggable']"));
Actions actn=new Actions(driver);
actn.dragAndDropBy(element, 50, 50).build().perform();
}

35.   What is the basic use of Firefox profiles and how can we use them using selenium?
A profile in Firefox is a collection of bookmarks, browser settings, extensions, passwords, and history; in short, all of your personal settings.
We use them to change user agent, changing default download directory, changing versions etc.
http://code.google.com/p/selenium/wiki/FirefoxDriver

36.   Customize the name of file going to be  downloaded?
You have to download AUTO IT.exe file and has to be install and later you have create .au3 file (in this file you have to specify the commands in  VB script  like your file  name, where have to save, it will be easy may be 3 or 4 steps ) using AUTOIT...then right click the .au3 file you have to compile ....after that you will get the .exe file with the name of .au3 file ..In eclipse you will give the code like this
<----ProcessBuildder ps = new ProcessBuilder("path of the .exe file of au3") .start();--->


37.   How to handle internationalisation through  web driver?
FirefoxProfile profile = new FirefoxProfile();
profile.set Preference("intl.accept_languages","jp");
Web driver driver = new FirefoxDriver(profile); driver.get(google.com) will open google in
Japanese Lang

38.   How to overcome same origin policy through web driver?
·         Proxy server.
DesiredCapabilities capability=new DesiredCapabilities.firefox();
capability.setCapability(CapabilityType.PROXY,"your desire proxy")
WebDriver driver=new FirefoxDriver(capability);

39. How to put text in Facebook search box using selenium web driver.
·         driver.findElement(By.xpath("//div[contains(@class, '_586i')]")).sendKeys("abc");

40. Difference between flex and flash application.
In flash there is no code just based on creativity(design) we will complete the work(time consuming process) whereas flex contain some small functions  which is integrated with mxml,PHP..(no tool is there to develop  flex we want to use the properties of css and style sheet)


41. How to get text from captcha image??
driver.findElement(By.xpath(".//*[@id='SkipCaptcha']")).click();
String attr = ie.findElement(By.xpath(".//*[@id='SkipCaptcha']")).getAttribute("value");
System.out.println("The value of the attribute 'Name' is " + attr);

42. Is there a way to click hidden LINK in web driver?
String Block1 = driver.findElement(By.id("element ID"));
JavascriptExecutor js1=(JavascriptExecutor)driver;
js1.executeScript("$("+Block1+").css({'display':'block'});");

43. What Class Extends Web Driver?
·   AndroidDriver, ChromeDriver, EventFiringWebDriver, FirefoxDriver, HtmlUnitDriver,
InternetExplorerDriver, IPhoneDriver, PhantomJSDriver, RemoteWebDriver, SafariDriver
44. What are the APIs that support Web Driver?
·         API are  nothing but collection of all selenium commands for Locating UI Elements
(WebElements),Fetching a Page,User Input  etc…

45. How to disable cookies in browser.
·         Using deleteAllVisibleCookies() in selenium

46. How to change user agent in Firefox by selenium  web driver.
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("general.useragent.override", "some UA string");
Web Driver driver = new FirefoxDriver(profile);

47. What is Selenese?
Selenese is HTML language based command, which is used in Selenium IDE.

48. Differences between QTP and selenium.
1) Selenium generates a proxy while starting browser. QTP does not
2) QTP uses only Vb script. Selenium is available in many languages
3) QTP is paid and selenium is free.
4) You can run script from a particular line in QTP but in selenium, you cannot.
5) Selenium works on all browsers. QTP only works on IE, mozilla. Support from chrome has been introduced lately.
6) QTP is more organized and user friendly
7) Selenium requires more technical skills
8) QTP can also be used on desktop based applications but selenium cannot be used

49. What is the MOST challenging test problem in my career in Automation?
In my career
·         Changing XPATHS' between testing server and production server-by keeping generic xpath
·         Keep separate property files for production and UAT
·         automating flash apps
·         Mobile Automation

50. “Suppose developer changed the existing image to new image with same xpath. Is test case pass or fail?" ·         Pass

51. How to handle network latency using selenium?
·         Using driver.manage.pageLoadingtime for network latency

52. How does u handle dynamic elements without using  xpath (with example?)
·         By using classname or css.

53. What are the different types of driver implementation?
·         AndroidDriver, AndroidWebDriver, ChromeDriver, EventFiringWebDriver, FirefoxDriver, HtmlUnitDriver, InternetExplorerDriver, IPhoneDriver, IPhoneSimulatorDriver, RemoteWebDriver, SafariDriver, WebDriverBackedSelenium

54. Code for Opening Firefox browser?
·         Webdriver driver=new FireFoxdriver();

55. Which repository you have used to store the test  scripts?

I have created scripts in excel file and store them in Test cases folder under src .

 56. What are the different assertions in SIDE?
Assertions are like Assessors, but they verify that the state of the application conforms  to what is expected. Examples include "make sure the page title is X" and "verify that this  check box is checked".

57. How to store a value which is text box using  web driver?
driver.findElement(By.id("your Textbox")).sendKeys("your keyword");

58. How to handle alerts and confirmation boxes.
Confirmation boxes and Alerts are handled in same way in selenium.
var alert = driver.switchTo().alert();
alert.dismiss();  //Click Cancel or Close window operation
alert.accept();   //Click OK
Handle Confirmation boxes via JavaScript,
driver.executeScript("window.confirm = function(message){return true;};");

59. How to mouse hover on an element?
Actions action = new Actions(webdriver);
WebElement we = webdriver.findElement(By.xpath("html/body/div[13]/ul/li[4]/a"));
action.moveToElement(we).moveToElement(webdriver.findElement(By.xpath("/expression-here"))).click().build().perform();

60. How to switch between the windows?
private void handlingMultipleWindows(String windowTitle) {
            Set<String> windows = driver.getWindowHandles();
            for (String window : windows) {
                driver.switchTo().window(window);
                if (driver.getTitle().contains(windowTitle)) {   return;   }     }     }


61. How to switch between frames?

WebDriver's driver.switchTo().frame() method takes one of the three possible arguments:·        

62. What is actions class in web driver?
Actions class with web Driver help is Sliding element, Resizing an Element, Drag & Drop,
hovering a mouse, especially in a case when dealing with mouse over menus.

63. Difference between the selenium1.0 and selenium 2.0?
Selenium 1 = Selenium Remote Control.
Selenium 2 = Selenium Web driver, which combines elements of Selenium 1 and Web driver.

64. Difference between find element () and  findelements ()?
findElement() :
Find the first element within the current page using the given "locating mechanism".
Returns a single WebElement.
findElements() :
Find all elements within the current page using the given "locating mechanism".
Returns List of Web Elements.

65. How to take the screen shots in seelnium2.0?

11. What is the default time for selenium Ide and webdriver?
Default timeout in selenium ide is 30 seconds.
For web driver go to below URL:
12. Write down scenarios which we can't automate?
Barcode Reader, Captcha etc.

66. In TestNG I have some test's  Test1-Test2-Test3-Test4-Test5I want to run my execution order is Test5-Test1-Test3-Test2-Test4.How do you set the execution order can you explain for that?
·         Use priority parameter in @test annotation or TestNG annotations.
67. Differences between jxl and ApachePOI.
·         jxl does not support  XLSX files
·         jxl exerts less load on memory as compared to ApachePOI
·         jxl doesn't support rich text formatting while ApachePOI does.
·         jxl has not been maintained properly while ApachePOI is more up to date.
·         Sample code on Apache POI is easily available as compare to jxl.

68. How to ZIP files in Selenium with an Example?

69. What is default port no?
4444

70. If Default port no is busy how to change port no?
We can use any port number which is valid.. First create an object to remote control configuration.
Use 'setPort' method and provide valid port number(4545,5555,5655, etc).. There after attach this
remote control configuration object to selenium server..i.e
RemoteControlConfiguration r= new RemoteControlConfiguration();
r.setPort(4567);
SeleniumServer s= new SeleniumServer(r);


71. Does Selenium support https protocols?  Yes
72. "I want to find the location of ""b"" in the below  code, how can I find out without using xpath, name, id, csslocator, index.<div><Button>a</button> <Button>b</button><Button>c</button></div>
    ?      driver.findElement(By.xpath("//*[contains(text(),'b')]")).click(); or
?        //div/button[contains(text(),'b']
·     
73. How to do Applet testing using selenium?
Please see below URLs:
http://docs.codehaus.org/display/FEST/Selenium
https://code.google.com/p/festselenium/

1 comment: