Interview Questions For Selenium with Java

by Bharathkumar, on Sep 8, 2022 6:34:28 PM

Interview Questions (15)

Q1. What is test automation or automation testing?

Ans: Automation testing is used to automate the manual testing. It is a process of automating the manual process to test the application/system under test. It uses separate testing tools which facilitate you to create test scripts which can be executed repeatedly and doesn't need any manual intervention.

Q2. What are the advantages of automation testing?

Ans:

  • It supports execution of repeated test cases.
  • It facilitates parallel execution.
  • It aids in testing a large test matrix.
  • It improves accuracy because there are no chances of human errors.
  • It saves time and money.

Q3. What is selenium? What are the different components of selenium?

Ans: Selenium is one of the most popular automated testing suites. It is browser automation tool which lets you automated operations like click, type and selection from a drop down of a web page. It is designed to support and encourage automation testing of functionalities of web based applications and a wide range of browsers and platforms. It is one of the most accepted tools amongst the testing professional due to its existence in the open source community.

Selenium is not just a single tool rather than it is a package of several testing tools and that?s why it is referred as a suite. Each of these tools is designed to cater different testing and test environment requirement.

Q4. What is Selenium 1.0?

Ans: Selenium 1.0 is popularily known as Selenium Remote Control (Selenium RC). It is a library available in wide variety of languages. The main reason to use Selenium RC was that Selenium IDE was incapable to execute tests in browsers other than Selenium IDE and the limitation of language Selenese used in Selenium IDE.

Q5. What is Selenium IDE?

Ans: Selenium IDE is a firefox plug-in. It is used to record and replay tests in firefox browser. It is used only with firefox browser.

Q6. What is selenium 2.0?

Ans: Selenium 2.0 is a tool which is a combination of web testing tools Selenium RC and WebDriver.

Q7. Why is selenium selected as a test tool?

Ans: Selenium is used as a testing tool because:

  • It is free and open source.
  • It has a large user base and helping communities.
  • Compatible on different platforms i.e. Windows, Mac OS, Linux etc.
  • Have cross browser compatibility (Chrome, Firefox, IE, Safari etc.)
  • Support multiple programming languages ( Java, C#, Ruby, PERL, Python etc.)
  • Support distributed testing.

Q8. What are selenium supporting testing types?

Ans: Selenium supports two types of testing:

  1. Functional Testing.
  2. Regression Testing.

Q9. What are the limitations of selenium?

Ans: Selenium has following limitations:

  • It can be used only to test web based application.
  • Mobile applications can not be tested using selenium.
  • You can not test captcha and bar code by using selenium.
  • The user must have the knowledge of programming language for using selenium.
  • Reports can only be generated using third party tools like TestNG or Junit.

Q10. What is selenese?

Ans: Selenese is a lanuage which is used for writing test script in selenium IDE.

Q11. Describe the different types of locators in Selenium?

Ans: Locator is an address which identifies a web element uniquely within the web page.

There are different types of locators in Selenium to identify web elements accurately and precisely.

These are:

  • ID
  • ClassName
  • Name
  • TagName
  • LinkText
  • PartialLinkText
  • Xpath
  • CSS Selector
  • DOM

Q12. What is an Xpath?

Ans: Xpath is used to locate a web element based on its XML path. It can be used to locate HTML elements.

Q13. Which is the latest Selenium tool?

Ans: The latest Selenium tool is WebDriver.

Q14. What are the different types of Drivers that WebDriver contains?

Ans: These are the different drivers available in WebDriver:

  • FirefoxDriver
  • InternetExplorerDriver
  • ChromeDriver
  • SafariDriver
  • OperaDriver
  • AndroidDriver
  • IPhoneDriver
  • HtmlUnitDriver

Q15. What are the different types of annotations which are used in Selenium?

Ans: JUnit annotations which can be used are:

  • Test
  • Before
  • After
  • Ignore
  • BeforeClass
  • AfterClass
  • RunWith

Q16. What is Selenium Grid?

Ans: Selenium Grid facilitates you to distribute your tests on multiple machines and all of them at the same time. So, you can execute tests on Internet Explorer on Windows and Safari on Mac machine using the same text script. It reduces the time of test execution and provides quick feedback.

Q17. Where the result is seen of Test Execution in Selenium IDE?

Ans: The result of test execution is displayed in a Log Window in Selenium IDE.

Q18. Can you edit tests in Selenium IDE?

Ans: Yes, tests in Selenium IDE can be edited. There are two ways to edit tests in Selenium IDE.

  1. By Table views
  2. Looking into the source code

Q19. Can you use html id and name while using Selenium IDE?

Ans: Yes, You can use html id and name as it is available in Selenium IDE.

Q20. What are the WebDriver supported Mobile Testing Drivers?

Ans: WebDriver supported "mobile testing drivers" are:

  • AndroidDriver.
  • IphoneDriver.
  • OperaMobileDriver.

Q21. What are the popular programming languages supported by Selenium WebDriver to write Test Cases?

Ans:

  • JAVA.
  • PHP.
  • Python.
  • C#.
  • Ruby.
  • Perl.

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

Ans:  Assert: Assert command checks if the given condition is true or false. If the condition is true, the program control will execute the next phase of testing, and if the condition is false, execution will stop and nothing will be executed.

Verify: Verify command also checks if the given condition is true or false. It doesn't halts program execution i.e. any failure during verification would not stop the execution and all the test phases would be executed.

Q23. What is the difference between "/" and "//" in Xpath?

Ans:  Single Slash "/": Single slash is used to create Xpath with absolute path.

Double Slash "//": Double slash is used to create Xpath with relative path.

Q24. What is the difference between driver.get() and driver.navigate.to()?

Ans:  Both methods can be used to navigate to a url but the driver.get() is a convenient way to navigate to a url. The driver.navigate() does the same function as the driver.navigate().to(?url?) but it also has other functions, such as:

  • driver.navigate().back()
  • driver.navigate().forward()
  • driver.navigate().refresh()

Q25. What is the difference between implicit wait and explicit wait in selenium webdriver?

Ans: Implicit Wait: In Implicit wait, if WebDriver cannot find an element in the Document Object Model (DOM), it will wait for a defined amount of time for the element to appear in the DOM. The Implicit wait may slow down your tests, because once set, the implicit wait is set for the life of the WebDriver object's instance.

An example of Implicit Wait:

  • driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

Explicit Wait:

Explicit waits are better than implicit wait. Unlike an implicit wait, you can write custom code or conditions for wait before proceeding further in the code.

An explicit wait can be used where synchronization is needed, for example the page is loaded but we are still waiting for a call to complete and an element to appear.

An example of Implicit Wait: 

  • WebDriverWait wait = new WebDriverWait(driver, 10);
  • wait.until(ExpectedConditions.titleContains("selenium"));

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

Q27. What is the difference between "type" and "typeAndWait" command?

Ans: "type" command is used to type keyboard key values into text box of software web application. It can also be used for selecting values of combo box whereas "typeAndWait" command is used when your typing is completed and software web page start reloading. This command will wait for software application page to reload. If there is not page reload event on typing, you have to use simple "type" command.

Q28. What is the difference between sleep() and setSleep() method?

Ans: Sleep() and setSleep() both methods are used to delay the speed of execution.

Thread.sleep (): It is used to stop the current (java) thread for the specified period of time. It's done only once.

  • It takes a single argument in integer format.
  • For Example: thread.sleep(5000)- It will wait for 5 seconds.
  • It waits only once at the command given at sleep.

SetSpeed (): It will stop the execution for every selenium command for specific amount of time.

  • It takes a single argument in integer format.
  • For Example: selenium.setSpeed("5000")- It will wait for 5 seconds.
  • It runs each command after setSpeed delay by the number of milliseconds mentioned in set Speed.

Q29. What is the difference between find element () and findElements ()?

Ans: find element (): It is used to find the first element within the current page using the given "locating mechanism". It returns a single WebElement.

findElements () : It uses the given "locating mechanism" to find all the elements within the current page. It returns a list of web elements.

Q30. How to type in a text box using Selenium?

Ans: To type in a text box, we use sendKeys("String to be entered") to insert string in the text box.

Syntax: 

  • WebElement username = drv.findElement(By.id("Email"));
  • // entering username
  • username.sendKeys("sth");

Q31. What is JUnit?

Ans: JUnit is an open source testing framework for java applications. It is introduced by Apache.

Q32. What is JUnit Annotation?

Ans: Annotation is a process of adding a special form of syntactic meta-data to Java source code. Variables, parameters, packages, methods and classes are annotated some of the JUnit annotations.

Q33. What are the four parameters that you need to pass in Selenium?

Ans: The four parameters that you have to pass in Selenium are:

  1. Host.
  2. Port Number.
  3. Browser.
  4. URL.

Q34. How can you "submit" a form using Selenium ?

Ans: 
  1. WebElement el  =  driver.findElement(By.id("ElementID"));
  2. el.submit();

Q35. What is the difference between close() and quit()?

Ans: The close() method closes the current browser only whereas quit() method closes all browsers opened by WebDriver.

Q36. What is wait? How many types of waits in selenium?

Ans: The concept of waits is introduced by Selenium Webdriver for AJAX based application. There are two types of waits:

  1. Implicit Wait
  2. Explicit Wait

Q37. What is the main disadvantage of implicit wait?

Ans: The main disadvantage of implicit wait is that it slows down test performance.

Another disadvantage of implicit wait is:

Suppose, you set the waiting limit to be 10 seconds and the elements appears in the DOM in 11 seconds, your tests will be failed because you told it to wait a maximum of 10 seconds.

Q38. How would you check if a check-box or radio button is selected?

Ans: You can use the isSelected() method to check if a check-box or radio button is selected.

Syntax: 

driver.FindElement(By.id("id_of_checkbox")).isSelected();
 

Q39. How would you do drag and drop in Selenium Webdriver?

Ans: You can do drag and drop in Selenium by using the following code:

  • Actions action = new Actions(driver);
  • WebElement start = driver.findElement(By.cssSelector(?div.source?));
  • WebElement end = driver.findElement(By.cssSelector(?div.target?));
  • action.dragAndDrop(start,end).perform();

Q40. How would you check if an element is visible on the page?

Ans: isDisplayed() method is used to check if an element is visible on the page. The return type of this method is Boolean so, if it returns true, the element is visible otherwise it is not. 

  • driver.findElement(By.id(?id_of_element?)).isDisplayed();

Q41. How would you check if a button is enabled on a page?

Ans: isEnabled() method is used to check if a button is enabled on a page. The return type of this method is Boolean so, if it returns true, the element is visible otherwise it is not. 

  • driver.findElement(By.id(?id_of_element?)).isEnabled();

Q42. What are the main technical problems occurred with Selenium tools?

Ans: Like other automation testing tools, selenium also facilitates you to record, edit and debug test cases. But there are some problems that affect the maintainability of recorded test cases. Sometimes it takes more time to maintain automated test cases than to perform manual testing. Another problem is complex id for an HTML element. If ID is auto generated, the recorder test cases can fail during playback.

Q43. Which is the post release validation with continuous integration automation tool?

Ans: These tools are:

  • Jenkins
  • Hudson
  • Quick Build
  • CruiseCont

Q44. What are the four parameters that have to be passed in Selenium?

Ans: Four parameters that have to be passed in selenium are:

  • Host
  • Port Number
  • Browser
  • URL

 

Topics:Interview Questions with Answers

Comments

Subscribe