Artoftesting Selenium Interview Questions

Ques.2 What is the use of driver.get(“URL”) and driver.navigate().to(“URL”) commands? Is there any difference between the two?

Ans. Both driver.get(“URL”) and driver.navigate().to(“URL”) commands are used to navigate to a URL passed as a parameter. There is a minor difference between the two commands-

  • driver.navigate() allows moving back and forward in browser history with the help of driver.navigate().forward() and driver.navigate().back() commands.
  • In the case of single-page applications (where the URL is appended by ‘#’ to navigate to different sections of the page)-driver.navigate().to() navigates to a particular section by changing the URL without refreshing the page. Whereas driver.get() refreshes the page. This refreshing of the page is also the primary reason why history is not maintained in the case of the driver.get() command.Reference – Stack overflow
  • Ques.9 How to prevent a test case from running using TestNG?

    Ans. A Test method can be disabled from getting executed by setting the “enabled” attribute as false.

    Ques.6 How can we handle window UI elements and window POP-ups using selenium?

    Ans. Selenium is used for automating web-based applications only(or browsers only). If we want to handle window GUI elements then we can use tools like AutoIT. AutoIT is a freeware used for automating Windows GUI. The AutoIt scripts follow the simple BASIC language-like syntax. Also, it can be easily integrated with Selenium tests.

    Ques.2 How can we submit a form in Selenium?

    Ans. Using the submit() method we can submit a form in selenium.

    Also, we can use the click() method for the same purpose.

    Ques.2 How can we type text in a textbox element using Selenium?

    Ans. With the help of the sendKeys() method, we can type text in a textbox-

    Ques. Can we move back and forward in the browser using Selenium?

    Ans. Yes, using driver.navigate().back() and driver.navigate().forward() commands, we can move backward and forward in a browser.

    Ques.6 How to handle the HTTPS website in Selenium or how to accept the SSL untrusted connection?

    Ans. Using profiles, we can handle accepting the SSL untrusted connection certificate. Profiles are basically a set of user preferences stored in a file.

    Ques.9 How can we make one test method dependent on others using TestNG?

    Ans. Using the ‘dependsOnMethods’ parameter inside @Test annotation in TestNG, we can make one test method run only after the successful execution of the dependent test method.

    Ques.8 Explain the line of code Webdriver driver = new FirefoxDriver();.

    Ans. This is one of the most frequently asked Selenium interview questions. In the line of code Webdriver driver = new FirefoxDriver(); ‘WebDriver’ is an interface and we are creating an object of type WebDriver instantiating an object of FirefoxDriver class.

    Ques. What is the fundamental difference between XPath and CSS selectors?

    Ans. Using driver.navigate().refresh() command. Using sendKeys(Keys.F5) on any textbox on the webpage. Using driver.get(“URL”) on the current URL or using driver.getCurrentUrl() Using driver.navigate().to(“URL”) on the current URL or

    Ques. What are some advantages of the Selenium grid?

    Ans. The advantages of the Selenium grid are-

  • It allows running test cases in parallel thereby saving test execution time.
  • Multi-browser testing is possible using the Selenium grid by running the test on machines having different browsers.
  • Additionally, we can do multi-platform testing by configuring nodes having different operating systems.
  • Ques.5 What are some commonly encountered exceptions in Selenium?

    Ans. Some of the commonly seen exceptions in Selenium are-

  • NoSuchElementException – When no element could be located by the locator provided.
  • ElementNotVisibleException – When an element is present in the DOM but is not visible.
  • NoAlertPresentException – When we try to switch to an alert box but the targetted alert is not present.
  • NoSuchFrameException – When we try to switch to a frame but the targetted frame is not present.
  • NoSuchWindowException – When we try to switch to a window but the targetted window is not present.
  • UnexpectedAlertPresentException – When an unexpected alert blocks the normal interaction of the driver.
  • TimeoutException – When a command execution gets a timeout.
  • InvalidElementStateException – When the state of an element is not appropriate for the desired action.
  • NoSuchAttributeException – When we are trying to fetch an attribute’s value but the attribute is not correct.
  • WebDriverException – When there is some issue with the driver instance preventing it from getting launched.
  • Top Selenium Interview Questions and Answers – ArtOfTesting

    Related Posts

    Leave a Reply

    Your email address will not be published. Required fields are marked *