Selenium Webdriver Interview Questions with Answer


1. Selenium doesn't support __________ to write programs (Test Scripts)
a) Java
b) Perl
c) VBScript
d) Python

2. __________ is an Advantage of Selenium WebDriver?
a) Supports Web based Applications only
b) No built-in Result Reporting facility
c) Open Source
d) No IDE

3. In webdriver, which methods navigates to a URL?
a) goToUrl("url")
b) navigate.to("url")
c) getUrl("url")
d) get("url")

4. Which of the following is the correct ‘Webdriver’ command to “delete all cookies in the browser”?
a) Driver.deleteAllCookies()
b) Driver.manage().deleteCookies()
c) Driver.manage().deleteAllCookies()
d) Driver.deleteCookies()

5. In webdriver, which of the following is a valid select statement that selects a value from a dropdown element?
a) All of the listed options
b) selectByIndex()
c) selectByValue()
d) selectByVisibleText()

6. In webdriver, selectAllOptions() is a valid command.
a) True
b) False

7. In webdriver, which of the following commands retrieves the text of  html element?
a) selectText()
b) getText()
c) getElementText()
d) getText(WebElement)

8. In webdriver, which command takes you forward by one page on the browser’s history?
a) navigate.forward()
b) Navigate.forward()
c) navigate().forward()
d) Navigate.forward
e) navigate_forward()

9. Consider the following code snippet
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.presenceOfElementLocated(by));
This is an example of an implicit wait.
a) True
b) False

10. Which of the following Selenium API enables running Selenium 1.0 tests in web driver?
a) Selenium RC
b) None of the listed options
c) Webdriver
d) WebDriverBackedSelenium

11. In WebDriver, which command can be used to enter values onto text boxes? Select the best answer.
a) type()
b) selenium.type()
c) driver.type("text")
d) sendKeys()
e) sendKeys("text")

12. Which command should be used to ensure Selenium applies wait time for all UI elements in the script?
a) Explicit wait
b) Fluent Wait
c) Implicit Wait
d) Sleep

13. Which of the following is the correct option to close all the opened browser sessions at one step?
a) Driver.close()
b) Driver.quit()
c) Driver.closeAll()
d) Driver.exit()

14. Which of the following is used to toggle a checkbox in a web form?
a) Element.toggle()
b) Element.click()
c) Element.set()
d) Element.select()

15. Which of the following will terminate the test when the check fails
a) Verify
b) Assert

16. How to switch between windows
a).switchto().window(Integer)
b).switchto().window(string)
c).switchto().window(Array)
d) .switchto().window(array list)

17. Which command to be used to get the text from Alert message popup
a) Alert alert = driver.switchTo().alert();
String message = alert.getText();
b) SwitchAlert alert = driver.switchalert();
String message = alert.getText();
c) Alert alert = driver.switchalert();
String message = alert.getText();

18. Identify the Invalid Xpath for Submit button
a) //*[@class=’submit’]
b) //div[contain(@class,’submit’)]
c) //div[@class=’submit’]
d) //div[contains(@class,’submit’)]

19. Implicit wait time is applied to all elements in your script and Explicit wait time is applied only for particular specified element.
a) True
b) False

20. In webdriver, which method closes the open browser?
a) quit()
b) terminate()
c) shutdown()
d) close()

21. What is the output of the following statement?
<div> <a id=’name’>Name 1 </a>
<a id=’name’>Name 2 </a></div>
driver.findElement(By.cssSelector(“#name”));

a) Output is Name 1
b) Output is Name 2
c) CSS selector syntax is incorrect

22. Select which are NOT the type of the locaters.
a) ID
b) Name
c) Password
d) Link Text

23. In webdriver, what is the method that counts the number of elements?
a) driver.getCountOfElements()
b) driver.findElement(By.id("search")).getCount()
c) driver.findElements(By.id("search")).size()
d) driver.findElements(By.id("search")).length()

24. Identify the correct statement about Implicit Wait-
a) An implicit wait is to tell WebDriver to poll the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available.
b) The default setting is 0.
c) Once set, the implicit wait is set for the life of the WebDriver object instance.
d) An implicit wait is the code you define to wait for a certain condition to occur before proceeding further in the code.

25. Identify the steps to instantiate the Chrome driver in correct sequence
a) 1. Using System Property set method get the path of chrome driver
    2. Initialize chrome driver Object with capabilities object as argument
    3. Open the URL
    4.  Set the capabilities of chrome browser
b) 1. Using System Property set method get the path of chrome driver
    2. Set the capabilities of chrome browser
    3. Initialize chrome driver Object with capabilities object as argument
    4. Open the URL
c) 1. Using System Property set method get the path of chrome driver
    2. Set the capabilities of chrome browser
    3. Open the URL
    4. Initialize chrome driver Object with capabilities object as argument
d) 1. Set the capabilities of chrome browser
    2. Initialize chrome driver Object with capabilities object as argument
    3. Using System Property set method get the path of chrome driver
    4.  Open the URL

26. Identify the valid command to handle pop ups in chrome browser
a) Alert objAlert = driver.switchTo().alert();); objAlert.accept();
b) driver.findElement(By.id(‘AlertId’)).sendkeys(Keys.Enter);
c) Alert objAlert = new Alert(driver); objAlert.accept();

27. Identify Incorrect URL for Console grid
a) http://localhost:portno
b.http://localhost:portno/grid/console
c.https://localhost:portno/grid/console

28. Select the variation which locates elements by the value of the “name” attribute in Web driver Selenium
a) By.name
b) By.nametag
c) By.tagname
d) By.nametags

29. Select the Get command which fetches the inner text of the element that you specify in Web driver Selenium.
a) getinnerText()
b) get_in_Text()
c) get_inner_Text()
d) getText()

30. Consider the following html snippet
      • Firefox
      • Google Chrome
      • Internet Explorer
      • Opera
      • Safari
Which CSS selector is a valid statement to select Opera?
a) css = li.contains("Opera")
b) css = ul.li(4)
c) css = ul > li:nth-of-type(4)
d) css = ul > li:nth-of-type(3)
e) css = ul.li:nth-child(4)

31. The following codes both print the same value
        System.out.println(driver.getTitle());
        System.out.println(driver.findElement(By.tagName(“title”)).getText())
a) True
b) False

32. To run a test on Firefox browser, you must have which of the following?
a) Firefox plug-ins are installed
b) Only Firefox browser is installed
c) GeckoDriver is installed, similar to IEDriver and ChromeDriver setup
d) Both GeckoDriver and Firefox browser are installed

33. Identify the correct code snippet to double click an element using selenium from the following:
a) WebElement el = driver.findElement(By.id(“Element”));
     Actions builder = new Actions(driver)
     Builder.doubleClick().build().perform()
b) WebElement el = driver.findElement(by.id(“ElementID”))
     Actions builder = new Actions(driver0;
     Buider.doubleClick().build()
c) WebElement el = driver.findElemet(by.id(“ElementID”))
     Actions builder = new Actions(driver)
     Buider.doubleClick().build()
d) WebElement el = driver.findElement(By.id(“ElementID”)
     Actions builder = new Actions(driver)
     Builder.doubleClick(el).build()perform()

34. Which of the following is the correct Webdriver statement to retrieve the row count of a Table?
a) All of the listed options
b) Driver.FindElements(By.Xpath(“//table[@id=’tableID’]/tr”)).size();
c) Driver.FindElements(By.Xpath(“//table[@id=’tableID’]/tr”)).getrowcount();
d) Driver.FindElements(By.Xpath(“//table[@id=’tableID’]/tr”)).getcount();

35. Which of the following features are applicable for both Test NG and Junit?
           I) Suite Test
          II) Group Test
         III) Parameterized Test object
         IV) Dependency Test
Select One:
a) I, II, III IV
b) I and II
c) I
d) I and III

36. What is the use of Desired Capabilities
a) It is used for Selenium Grid
b) It gives facility to set the properties of browser.
c) It is used to execute multiple test cases on multiple Systems with different browser with Different version and Different Operating System.
d) All of the above

37. A code snippet related to Fluent wait

   Example:
     Wait wait = new FluentWait(driver)
     .withTimeout(30, SECONDS)
     .pollingEvery(5, SECONDS)
     .ignoring(NoSuchElementException.class);

      1. Ignores NoSuchElementException
      2. Automatically adds NoSuchElementException
      3. Defines the maximum amount of time to wait for a condition
      4. Frequency with which to check the condition
Identify the valid options based on above example
a) Option 1,3 & 4
b) Option 3 & 4
c) Option 2,3 & 4

38. Selenium Framework Component that supports Listener
a) Webdriver
b) TestNG
c) Junit
d) Selenium GRID

39. Identify the Invalid Syntax for Java script executor
a) WebDriver driver = new ChromeDriver();
     if (driver instanceof JavascriptExecutor) {
     ((JavascriptExecutor) driver).executeScript("alert('hello world');");
    }
b) JavascriptExecutor js = new JavascriptExecutor(driver);
    js.executeScript("arguments[0].click();", element);
c) JavascriptExecutor js = (JavascriptExecutor)driver;
    js.executeScript("arguments[0].click();", element);

40. Identify Invalid Syntax for refreshing the browser
a) driver.findElement(By.id("firstname-placeholder")).sendKeys(Keys.F5);
b) driver.refresh();
c) driver.get(driver.getCurrentUrl());
d) driver.findElement(By.id("firstname-placeholder")).sendKeys("\uE035");

41. Consider the following HTML code snippet
1
2
3
4

      driver.findElement(By.xpath(“//table/tr[1]/td”)).getText();
a) The above statement returns 1
b) The above statement returns 3
c) The xpath query is incorrect
d) webdriver statement is incorrect

42. Which method is used when you want to verify whether a certain check box, radio button, or option in a drop-down box is selected in Web driver Selenium
a) is_Selected()
b) isSelect()
c) isSelected()
d) is_Select()

43. Selenium is compatible with
a) CSS1.0 and CSS 2.0,
b) CSS1.0, CSS 2.0, and CSS 3.0 selectors.
c) CSS 2.0, and CSS 3.0 selectors.
d) CSS1.0, CSS 2.0, CSS 3.0 and CSS 4.0 selectors.

44. Which process use the JavaScript to find an element?
a) By DOM query
b) BY XPath query
c) BY CSS sector
d) All of these

45. To delete a cookie we need to call the deleteCookie method, passing in two parameters.
a) The first parameter is the name of the cookie, and the second parameter is where it was created.
b) The first parameter is where it was created, and the second parameter is the name of cookie.
c) None of these

46. Selects all the parent, grandparent, and so on of the element is related to which axis name in Selenium:
a) Ancestor
b) Preceding
c) Parent
d) All of these.

47. You have to use ‘Xpath’ to locate the following input element:
      <input id=”fk-top-search-box” class=”search-bar-text fk-font-13 ac_input” type=”text” autofocus=”autofocus” value=”” name=”q” />

Identify the invalid Xpath from the following options.

a) //input[starts-with(@id, ‘fk-top-search-box’) and contains(@class, ‘fk-font-13)]
b) //input[@id=’fk-top-search-box’]
c) //input[starts-with(@class, ”search-bar-text”)]
d) //input[starts-with(@id, ‘top-search-box’) and contains(@class, ‘font-13’)]

48. Select the method which performs a context-click (right click) at the current mouse location.
a) click_Context()
b) context.Click()
c) contextClick()
d) context_Click()

49. The // tells the query that
a) It needs to stop at the first element that it finds.
b) This is comment
c) The path of the file or folder
d) All of these

50. Which of the following API enables running Selenium 1.0  tests in Webdriver
a) Webdriver
b) None of the listed options
c) WebdriverbackedSelenium
d) Selenium RC

Answers for the above questions,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
c
c
d
c
a
b
b
c
b
d
e
c
b
b
b
b
a
b
a
d
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
a
c
c
c
b
a
c
a
d
c
a
d
d
b
c
d
a
b
b
b
41
42
43
44
45
46
47
48
49
50
a
c
b
a
a
a
d
c
a
c

Popular posts from this blog

Selenium IDE Interview Questions with Answer

DLL to Jar file conversion