Selenium Interview Questions and Answers

Selenium Interview Questions and Answers

1. What is Automation Testing?

Ans. Automation testing or Test Automation is a process of automating the manual process to test the application/system under test. Automation testing involves the use of a separate testing tool which lets you create test scripts which can be executed repeatedly and doesn’t require any manual intervention.

2.What are the benefits of Automation Testing?

Ans.Benefits of Automation testing are :
1-Supports execution of repeated test cases
2-Aids in testing a large test matrix
3-Enables parallel execution
4-Encourages unattended execution
5-Improves accuracy thereby reducing human-generated errors
6-Saves time and money.

3.Why should Selenium be selected as a test tool?

Ans.
1-is a free and open source
2-have a large user base and helping communities
have cross Browser compatibility (Firefox, Chrome, Internet Explorer, Safari etc.)
3-have great platform compatibility (Windows, Mac OS, Linux etc.)
4-supports multiple programming languages (Java, C#, Ruby, Python, Pearl etc.)
5-has fresh and regular repository developments
supports distributed testing.
Q.4.What are the testing types that can be supported by Selenium?

4.What are the testing types that can be supported by Selenium?

Ans.Selenium supports the following types of testing:
1-Functional Testing
2-Regression Testing.

5. What are the limitations of Selenium?

Ans. Following are the limitations of Selenium:
1-Selenium supports testing of only web-based applications
2-Mobile applications cannot be tested using Selenium
3-Captcha and Barcode readers cannot be tested using Selenium
4-Reports can only be generated using third-party tools like TestNG or JUnit.
5-As Selenium is a free tool, thus there is no ready vendor support through the user can find numerous helping communities.
6-The user is expected to possess prior programming language knowledge.

6. When should I use Selenium IDE?

Ans. Selenium IDE is the simplest and easiest of all the tools within the Selenium Package. Its record and playback feature makes it exceptionally easy to learn with minimal acquaintances to any programming language. Selenium IDE is an ideal tool for a naïve user.

7. What is an XPath?

Ans.XPath is used to locate a web element based on its XML path. XML stands for Extensible Markup Language and is used to store, organize and transport arbitrary data. It stores data in a key-value pair which is very much similar to HTML tags. Both being markup languages and since they fall under the same umbrella, XPath can be used to locate HTML elements.The fundamental behind locating elements using XPath is the traversing between various elements across the entire page and thus enabling a user to find an element with the reference of another element.

8.When should I use Selenium Grid?

Ans.Selenium Grid can be used to execute same or different test scripts on multiple platforms and browsers concurrently so as to achieve distributed test execution, testing under different environments and saving execution time remarkably.

9.How can we get a text of a web element?

Ans.Get command is used to retrieve the inner text of the specified web element. The command doesn’t require any parameter but returns a string value. It is also one of the extensively used commands for verification of messages, labels, errors etc displayed on the web pages.Syntax:
String Text = driver.findElement(By.id(“Text”)).getText();

10.How to assert the title of the web page?

Ans.//verify the title of the web page
assertTrue(“The title of the window is incorrect.”,driver.getTitle().equals(“Title of the page”));

11.Which language is used in Selenium IDE?

Ans.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.

12.What is Selenium Grid?

Ans.Selenium grid lets you distribute your tests on multiple machines and all of them at the same time. Hence you can execute test 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 executioin and provides quick feedback to stack holders.helps in reducing the time of test execution and provides quick feedback to stack holders.

13.Can I build test suite using Selenium IDE??

Ans.Yes, you can first record individual test cases and then group all of them in a test suite. Entire test suite could be executed instead of executing individual tests.

14.There is id, name, XPath, CSS locator, which one should I use?

Ans. If there are constant name/id available than 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.

15. Selenium: Unable to connect to the remote server?

Ans. Selenium: Unable to connect to the remote server?.

16. How will you find an element using Selenium?

Ans.In Selenium every object or control in a web page is referred as an elements, there are different ways to find an element in a web page they are
ID
Name
Tag
Attribute
CSS
Linktext
PartialLink Text
Xpath etc

17.Explain what is assertion in Selenium and what are the types of assertion?

Ans.Assertion is used as a verification point. It verifies that the state of the application conforms to what is expected. The types of assertion are “assert” , “verify” and “waitFor”.

18.Mention what is the use of X-path?

Ans.X-Path is used to find the WebElement in web pages. It is also useful in identifying the dynamic elements.

19. Explain the difference between single and double slash in X-path?

Ans.

Single slash ‘/ ’
Single slash ( / ) start selection from the document node
It allows you to create ‘absolute’ path expressions
Double Slash ‘// ’

Double slash ( // ) start selection matching anywhere in the document
It enables to create ‘relative’ path expressions

20.List out the technical challenges with Selenium?

Ans.ITechnical challenges with Selenium are
Selenium supports only web based applications
It does not support the Bitmap comparison
For any reporting related capabilities have to depend on third party tools
No vendor support for tool compared to commercial tools like HP UFT
As there is no object repository concept in Selenium, maintainability of objects becomes difficult

21.What is the difference between type keys and type commands?

Ans.TypeKeys() will trigger JavaScript event in most of the cases whereas .type() won’t. Type key populates the value attribute using JavaScript whereas .typekeys() emulates like actual user typing

22. What is the difference between verify and assert commands?

Ans. Assert: Assert allows to check whether an element is on the page or not. The test will stop on the step failed, if the asserted element is not available. In other words, the test will terminated at the point where check fails.Verify: Verify command will check whether the element is on the page, if it is not then the test will carry on executing. In verification, all the commands are going to run guaranteed even if any of test fails.

23. What is JUnit Annotations and what are different types of annotations which are useful?

Ans.In JAVA a special form of syntactic meta-data can be added to Java source code, this is know as Annotations. Variables, parameters, packages, methods and classes are annotated some of the Junit annotations which can be useful are
Test
Before
After
Ignore
BeforeClass
AfterClass
RunWith

24.While using click command can you use screen coordinate?

Ans. To click on specific part of element, you would need to use clickAT command. ClickAt command accepts element locator and x, y co-ordinates as arguments- clickAt (locator, cordString)

25. What are the advantages of Selenium?

Ans.It supports C#, PHP, Java, Perl, Phython
It supports different OS like Windows, Linux and Mac OS
It has got powerful methods to locate elements (Xpath, DOM , CSS)
It has highly developer community supported by Google

26.Why testers should opt for Selenium and not QTP?

Ans.Selenium is more popular than QTP as
Selenium is an open source whereas QTP is a commercial tool
Selenium is used specially for testing web based applications while QTP can be used for testing client server application also
Selenium supports Firefox, IE, Opera, Safari on operating systems like Windows, Mac, Linux etc. however QTP is limited to Internet Explorer on Windows.
Selenium supports many programming languages like Ruby, Perl, Python whereas QTP supports only VB script

27.What are the four parameter you have to pass in Selenium?

Ans.Four parameters that you have to pass in Selenium are
Host
Port Number
Browser
URL

28. What is the difference between setSpeed() and sleep() methods?

Ans.

Both will delay the speed of execution.Thread.sleep () : It will stop the current (java) thread for the specified period of time. Its done only once
It takes a single argument in integer format
Ex: thread.sleep(2000)- It will wait for 2 seconds

It waits only once at the command given at sleep
SetSpeed () : For specific amount of time it will stop the execution for every selenium command.

It takes a single argument in integer format
Ex: selenium.setSpeed(“2000”)- It will wait for 2 seconds

Runs each command after setSpeed delay by the number of milliseconds mentioned in set Speed
This command is useful for demonstration purpose or if you are using a slow web application

29.What is same origin policy? How you can avoid same origin policy?

Ans. The “Same Origin Policy” is introduced for security reason, and it ensures that content of your site will never be accessible by a script from another site. As per the policy, any code loaded within the browser can only operate within that website’s domain.To avoid “Same Origin Policy” proxy injection method is used, in proxy injection mode the Selenium Server acts as a client configured HTTP proxy , which sits between the browser and application under test and then masks the AUT under a fictional URL

30.What is heightened privileges browsers?

Ans. The purpose of heightened privileges is similar to Proxy Injection, allows websites to do something that are not commonly permitted. The key difference is that the browsers are launced in a special mode called heightened privileges. By using these browser mode, Selenium core can open the AUT directly and also read/write its content without passing the whole AUT through the Selenium RC server.

31.How you can use “submit” a form using Selenium ?

Ans. You can use “submit” method on element to submit form-element.submit () ;Alternatively you can use click method on the element which does form submission

32.Mention what is the difference between Implicit wait and Explicit wait?

Ans. Implicit Wait: Sets a timeout for all successive Web Element searches. For the specified amount of time it will try looking for element again and again before throwing a NoSuchElementException. It waits for elements to show up.Explicit Wait : It is a one-timer, used for a particular search.

33. Which attribute you should consider throughout the script in frame for “if no frame Id as well as no frame name”?

Ans. You can use…..driver.findElements(By.xpath(“//iframe”))….This will return list of frames.You will need to switch to each and every frame and search for locator which we want.Then break the loop

34. Explain what is the difference between find elements () and find element () ?

Ans.find element ():It finds the first element within the current page using the given “locating mechanism”. It returns a single WebElementfindElements () : Using the given “locating mechanism” find all the elements within the current page. It returns a list of web elements.

35. Explain what are the JUnits annotation linked with Selenium?

Ans. he JUnits annotation linked with Selenium are@Before public void method() – It will perform the method () before each test, this method can prepare the test
@Test public void method() – Annotations @Test identifies that this method is a test method environment
@After public void method()- To execute a method before this annotation is used, test method must start with test@Before

1. What is Automation Testing?

Ans. Automation testing or Test Automation is a process of automating the manual process to test the application/system under test. Automation testing involves the use of a separate testing tool which lets you create test scripts which can be executed repeatedly and doesn’t require any manual intervention.

2.What are the benefits of Automation Testing?

Ans.Benefits of Automation testing are :
1-Supports execution of repeated test cases
2-Aids in testing a large test matrix
3-Enables parallel execution
4-Encourages unattended execution
5-Improves accuracy thereby reducing human-generated errors
6-Saves time and money.

3.Why should Selenium be selected as a test tool?

Ans.
1-is a free and open source
2-have a large user base and helping communities
have cross Browser compatibility (Firefox, Chrome, Internet Explorer, Safari etc.)
3-have great platform compatibility (Windows, Mac OS, Linux etc.)
4-supports multiple programming languages (Java, C#, Ruby, Python, Pearl etc.)
5-has fresh and regular repository developments
supports distributed testing.
Q.4.What are the testing types that can be supported by Selenium?

4.What are the testing types that can be supported by Selenium?

Ans.Selenium supports the following types of testing:
1-Functional Testing
2-Regression Testing.

5. What are the limitations of Selenium?

Ans. Following are the limitations of Selenium:
1-Selenium supports testing of only web-based applications
2-Mobile applications cannot be tested using Selenium
3-Captcha and Barcode readers cannot be tested using Selenium
4-Reports can only be generated using third-party tools like TestNG or JUnit.
5-As Selenium is a free tool, thus there is no ready vendor support through the user can find numerous helping communities.
6-The user is expected to possess prior programming language knowledge.

6. When should I use Selenium IDE?

Ans. Selenium IDE is the simplest and easiest of all the tools within the Selenium Package. Its record and playback feature makes it exceptionally easy to learn with minimal acquaintances to any programming language. Selenium IDE is an ideal tool for a naïve user.

7. What is an XPath?

Ans.XPath is used to locate a web element based on its XML path. XML stands for Extensible Markup Language and is used to store, organize and transport arbitrary data. It stores data in a key-value pair which is very much similar to HTML tags. Both being markup languages and since they fall under the same umbrella, XPath can be used to locate HTML elements.The fundamental behind locating elements using XPath is the traversing between various elements across the entire page and thus enabling a user to find an element with the reference of another element.

8.When should I use Selenium Grid?

Ans.Selenium Grid can be used to execute same or different test scripts on multiple platforms and browsers concurrently so as to achieve distributed test execution, testing under different environments and saving execution time remarkably.

9.How can we get a text of a web element?

Ans.Get command is used to retrieve the inner text of the specified web element. The command doesn’t require any parameter but returns a string value. It is also one of the extensively used commands for verification of messages, labels, errors etc displayed on the web pages.Syntax:
String Text = driver.findElement(By.id(“Text”)).getText();

10.How to assert the title of the web page?

Ans.//verify the title of the web page
assertTrue(“The title of the window is incorrect.”,driver.getTitle().equals(“Title of the page”));

11.Which language is used in Selenium IDE?

Ans.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.

12.What is Selenium Grid?

Ans.Selenium grid lets you distribute your tests on multiple machines and all of them at the same time. Hence you can execute test 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 executioin and provides quick feedback to stack holders.helps in reducing the time of test execution and provides quick feedback to stack holders.

13.Can I build test suite using Selenium IDE??

Ans.Yes, you can first record individual test cases and then group all of them in a test suite. Entire test suite could be executed instead of executing individual tests.

14.There is id, name, XPath, CSS locator, which one should I use?

Ans. If there are constant name/id available than 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.

15. Selenium: Unable to connect to the remote server?

Ans. Selenium: Unable to connect to the remote server?.

16. How will you find an element using Selenium?

Ans.In Selenium every object or control in a web page is referred as an elements, there are different ways to find an element in a web page they are
ID
Name
Tag
Attribute
CSS
Linktext
PartialLink Text
Xpath etc

17.Explain what is assertion in Selenium and what are the types of assertion?

Ans.Assertion is used as a verification point. It verifies that the state of the application conforms to what is expected. The types of assertion are “assert” , “verify” and “waitFor”.

18.Mention what is the use of X-path?

Ans.X-Path is used to find the WebElement in web pages. It is also useful in identifying the dynamic elements.

19. Explain the difference between single and double slash in X-path?

Ans.

Single slash ‘/ ’
Single slash ( / ) start selection from the document node
It allows you to create ‘absolute’ path expressions
Double Slash ‘// ’

Double slash ( // ) start selection matching anywhere in the document
It enables to create ‘relative’ path expressions

20.List out the technical challenges with Selenium?

Ans.ITechnical challenges with Selenium are
Selenium supports only web based applications
It does not support the Bitmap comparison
For any reporting related capabilities have to depend on third party tools
No vendor support for tool compared to commercial tools like HP UFT
As there is no object repository concept in Selenium, maintainability of objects becomes difficult

21.What is the difference between type keys and type commands?

Ans.TypeKeys() will trigger JavaScript event in most of the cases whereas .type() won’t. Type key populates the value attribute using JavaScript whereas .typekeys() emulates like actual user typing

22. What is the difference between verify and assert commands?

Ans. Assert: Assert allows to check whether an element is on the page or not. The test will stop on the step failed, if the asserted element is not available. In other words, the test will terminated at the point where check fails.Verify: Verify command will check whether the element is on the page, if it is not then the test will carry on executing. In verification, all the commands are going to run guaranteed even if any of test fails.

23. What is JUnit Annotations and what are different types of annotations which are useful?

Ans.In JAVA a special form of syntactic meta-data can be added to Java source code, this is know as Annotations. Variables, parameters, packages, methods and classes are annotated some of the Junit annotations which can be useful are
Test
Before
After
Ignore
BeforeClass
AfterClass
RunWith

24.While using click command can you use screen coordinate?

Ans. To click on specific part of element, you would need to use clickAT command. ClickAt command accepts element locator and x, y co-ordinates as arguments- clickAt (locator, cordString)

25. What are the advantages of Selenium?

Ans.It supports C#, PHP, Java, Perl, Phython
It supports different OS like Windows, Linux and Mac OS
It has got powerful methods to locate elements (Xpath, DOM , CSS)
It has highly developer community supported by Google

26.Why testers should opt for Selenium and not QTP?

Ans.Selenium is more popular than QTP as
Selenium is an open source whereas QTP is a commercial tool
Selenium is used specially for testing web based applications while QTP can be used for testing client server application also
Selenium supports Firefox, IE, Opera, Safari on operating systems like Windows, Mac, Linux etc. however QTP is limited to Internet Explorer on Windows.
Selenium supports many programming languages like Ruby, Perl, Python whereas QTP supports only VB script

27.What are the four parameter you have to pass in Selenium?

Ans.Four parameters that you have to pass in Selenium are
Host
Port Number
Browser
URL

28. What is the difference between setSpeed() and sleep() methods?

Ans.

Both will delay the speed of execution.Thread.sleep () : It will stop the current (java) thread for the specified period of time. Its done only once
It takes a single argument in integer format
Ex: thread.sleep(2000)- It will wait for 2 seconds

It waits only once at the command given at sleep
SetSpeed () : For specific amount of time it will stop the execution for every selenium command.

It takes a single argument in integer format
Ex: selenium.setSpeed(“2000”)- It will wait for 2 seconds

Runs each command after setSpeed delay by the number of milliseconds mentioned in set Speed
This command is useful for demonstration purpose or if you are using a slow web application

29.What is same origin policy? How you can avoid same origin policy?

Ans. The “Same Origin Policy” is introduced for security reason, and it ensures that content of your site will never be accessible by a script from another site. As per the policy, any code loaded within the browser can only operate within that website’s domain.To avoid “Same Origin Policy” proxy injection method is used, in proxy injection mode the Selenium Server acts as a client configured HTTP proxy , which sits between the browser and application under test and then masks the AUT under a fictional URL

30.What is heightened privileges browsers?

Ans. The purpose of heightened privileges is similar to Proxy Injection, allows websites to do something that are not commonly permitted. The key difference is that the browsers are launced in a special mode called heightened privileges. By using these browser mode, Selenium core can open the AUT directly and also read/write its content without passing the whole AUT through the Selenium RC server.

31.How you can use “submit” a form using Selenium ?

Ans. You can use “submit” method on element to submit form-element.submit () ;Alternatively you can use click method on the element which does form submission

32.Mention what is the difference between Implicit wait and Explicit wait?

Ans. Implicit Wait: Sets a timeout for all successive Web Element searches. For the specified amount of time it will try looking for element again and again before throwing a NoSuchElementException. It waits for elements to show up.Explicit Wait : It is a one-timer, used for a particular search.

33. Which attribute you should consider throughout the script in frame for “if no frame Id as well as no frame name”?

Ans. You can use…..driver.findElements(By.xpath(“//iframe”))….This will return list of frames.You will need to switch to each and every frame and search for locator which we want.Then break the loop

34. Explain what is the difference between find elements () and find element () ?

Ans.find element ():It finds the first element within the current page using the given “locating mechanism”. It returns a single WebElementfindElements () : Using the given “locating mechanism” find all the elements within the current page. It returns a list of web elements.

35. Explain what are the JUnits annotation linked with Selenium?

Ans. he JUnits annotation linked with Selenium are@Before public void method() – It will perform the method () before each test, this method can prepare the test
@Test public void method() – Annotations @Test identifies that this method is a test method environment
@After public void method()- To execute a method before this annotation is used, test method must start with test@Before