Demo And First 3 Classes Free For All Courses & WhatsApp @ 9700779923 To Share Course Details.

Selenium Interview Question and Answers

1)What is the difference between QTP and Selenium?

A.Selenium

  • Selenium is Open source (free of cost)
  • Works on all OS (Windows, OS X, Linux, Solaris)
  • Tests only Web Applications
  • Works on almost all browsers (IE, Firefox, Safari, Opera)
  • Code can be made in any one language such as Java, C#, Ruby, Python, Pearl, php etc.
  • Html ID, Xpath, CSS, DOM, Link text
  • Repository objects There is no option, can record script in Selenium IDE, can spy objects using IE developer tool bar, Firebug and using http://saucelabs.com/builder
  • IDE sometimes does not record some events.
  • Set of Libraries, around 20MB (Need to include other supporting software)
  • Saucelabs.com, Element34, Commercial, Support.

QTP:

  • QTP is a Paid tool.
  • Works on Windows
  • Test’s web and desktop applications
  • Works on Firefox 3.5.x and IE
  • VB (visual Basic) Script
  • Object Properties, Repository objects
  • GUI Spy
  • Recording is a little reliable.
  • Around 1.5GB
  • From HP
2)What are the drawbacks with selenium IDE?
  • It is just a Record and Playback Tool.
  • Works on Windows
  • Test’s web and desktop applications
  • Works on Firefox 3.5.x and IE
  • VB (visual Basic) Script
  • Object Properties, Repository objects
  • GUI Spy
  • Recording is a little reliable.
  • Around 1.5GB
  • From HP
3)How many element locators are there in selenium and what are they?

There are 8 element locators. They are.

  1. Id
  2. Name
  3. Link Text
  4. Css selector
  5. Xpath
  6. Partial Link Text
  7. Class
  8. Tag name
4)What is the difference between "Single forward slash" and "Double forward slash"?

Single forward slash is used to move from parent node to immediate child node. Double forward slash- If it is used in the beginning of expression it will search in the entire HTML page and if it used in the middle of the expression it will search in its entire parent node.

5)How will you identify the Xpath for dynamic element?

By the help of independent and dependent element. First need to identify dependent and independent element. Identify the Xpath for independent element and move to it common parent until it covers both the dependent and independent element. Then identify the Xpath for dependent element by the help of independent element.

6)Tell me the functions used in Xpath.

i)Text()

ii)Contains()

7)What is Web driver?

Web driver is an automation tool which is used to automate a web application which has DOM structure.

8)What are the browsers & operating system supported by web driver?
  • Works on almost all browsers (IE, Firefox, Chrome, Safari, Opera)
  • Works on all OS (Windows, OS X, Linux, Solaris)
9)Can you name some of the methods under web driver or browser Driver?
  • findElement()
  • get()
  • close()
  • quit()
  • gettext()
  • getTitle()
  • getWindowHandles()
  • getCurrentUrl()
10)How do you validate a page?

By Using Title, Text, URL and Element Check points on the Page.

11)How do you get the Title of the page?

Comparing the expected title with the actual title from the application. To get the actual title we can use driver.getTitle().

12)How will you compare any text on the application page?

Text will generally be inside an html tag (span, td, div, p, b). To get the text we have to find the element and use the method getText().

13)How do you get the URL of the page?

By Using driver.getCurrentURL().

14)How do you verify whether a checkbox or radio button is selected or not?

By using driver.findElement(), we identify the element and we use isSelected() which returns us the Boolean value. We print the Boolean value and if it returns as true then the checkbox is selected and false if checkbox is unselected.

15)How do you verify whether a logo is displayed or not?

By using driver.findElement(), we identify the element and we use isDisplayed() which returns us the Boolean value. We print the Boolean value and if it returns as true then the Logo is displayed and if false Logo is not displayed.

16)How do you select an option from the "select drop down"?

By using driver.findElement(), we identify the select drop down element. We create Object for the Select class which takes Web Element as a constructor. Select class has three different mehods namely,

  • selectByIndex()
  • selectByvalue()
  • selectByVisibletext()

We use any one of those methods to select the option from the Select drop down.

17)Can you tell me how many options are there in "select drop down"?

By using driver.findElement(), we identify the select drop down element. We create Object for the Select class which takes Web Element as a constructor. Select class has a method getOptions which returns a list of Web Elements. By using a for loop, we can iterate and get the text of individual options.

How to print all the options in the "select drop down"?

To get all available options select class provides a method getoptions() which returns a collection of all the options in the select dropdown. This collection is represented as a list of WebElement. Using a for loop we can use iterate the list, get each element from the List WebElement print the next of each element (Text of the option tag or visibletext).

18)Can you print all the selected options in the "select drop down"?

To get all the selected options from a multi select list box, we can use the method getAllSelectedOptions() which returns a list of Web Element (collection of all the select options).We can use a for loop and get each selected option and print the next of each element.

19)How do you identify all the links in the page & print the text of all the links in the page?

By using driver.findElements(), we identify the list of Webelements. driver.findElements() returns us the list of Web Elements. We use for loop to iterate and print the text of each link.

20)How will you identify all the checkboxes in a page & check all the check boxes?

By using driver.findElements(), we identify the list of Webelements. driver.findElements() returns us the list of Web Elements. We use for loop to iterate and click each checkbox.

21)How do you select a date from Calender pop up?

Click on the calendar icon which displays us the calendar pop up. Select an xpath for the required date and click on the selected date by using the click().

22)Can you display ToolTip of an image?

Tooltips are of two kinds.

  • Generated from the title attribute of the element and this will appear when we mouse over on the element. This can be achieved by using getAttribute(“title”) which returns the string. The string is the tool tip of the element.
  • When we click on a particular element the pop up will be appeared with the text. This can be achieved by selecting the popup Web Element and by using getText() we get the text of the pop up.
23)How do you click on "OK" or "Cancel" on javascript alert or Confirmation pop up or Prompt pop up?

To handle Javascript alert or confirmation pop-up, we need to first switch to the pop up using driver.switchTo().alert() which will return on object of alert. Using this object, we can

  • click on ok using accept ().
  • click on cancel using dismiss ().
24)How can you get the text on javascript alert,Confirmation & Prompt pop up?

To handle Javascript alert or confirmation pop-up , we need to first switch to the pop up using driver.switchTo().alert() which will return on object of alert. Using this object, we can
1. Get the text on the pop-up using get text ().

25)How do you type text in prompt pop up?

1. Type the text on the pop-up using SendKeys().

26)How do you handle "Page on load authentication pop up”?

By passing the values in the url itself. Eg. http://admin:manager@demo.actitime.com

27)How do you achieve Synchronization in Webdriver?

driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

28)What are the different "waits" available in Webdriver?

1. Implicitly Wait.
2. Explicitly Wait.
3. Fluent Wait.

29)What is the difference between Implicitely Wait & Explicitely Wait?

Difference between Implicitely Wait & Explicitely Wait

Impicit Wait Explicit Wait
Implicit Wait time is applied to all the elements in the script Explicit Wait time is applied only to those elements which are intended by us
In Implicit wait, we need not specify "Expected Conditions" on the element to be located In Explicit Wait, we need to specify "ExpectedConditions" on the element to be located
It is recommended to use when the elements are located with the time frame specified in implicit waitIt is recommended to use when the elements to use when the elements are taking long time to load and also for verifying the property of the element like(visibilityOfElementLocated,elementTOBEClickable,ElementToBESelected)
30)How do you do File Upload in Web driver?

We can use driver.findelement() to find the element and use sendkeys() and pass the full path of the file as an argument to the sendkeys.

31)How do you File Download in Web driver?

To save a file to disk automatically without the pop up, we can take help of Firefox preference by using Firefox profile.

32)How do you work with New Browser, New Window or New Tab?

We have to transfer the control to the browser pop up using driver.switchTo().Window(). Window () accepts a string argument which is the window handle of the browser to switch to. We can get the window handles of all the browsers that was opened during that execution by using method.

Driver.getwindowhandles().getwindowhandles() returns a set which contains all the window handles. We can use an iterator and get each window handle by using the next ().

33)How do you perform right click using web driver?

By creating object for Actions class and Actions class has a method called moveToElement(WebElement). By passing the Webelement as a parameter and using the contextClick() the context menu is appeared. We use sendKeys() to pass the values in the context menu and select a value from the context menu. It is always required to use perform () method when we use Actions class methods.

34)How do you send tab keys using Web driver?

By creating object for Actions class and Actions class has a method called sendKeys() where we can send all the key board special key as parameter for the sendKeys(). It is always required to use perform () method when we use Actions class methods.

35)How do you do drag and drop using web driver?

By creating object for Actions class and Actions class has a method called dragAndDrop(source,target). We pass source web element and target web element to dragAndDrop() and we perform drag and drop. It is always required to use perform () method when we use Actions class methods.

36)How do you launch IE browser and chrome browser?

By using setPreferences(Key,Value) we open IE and chrome browser.

37)What is the latest version of selenium standalone server you had used?

2.53----2.53.1

38)How do you handle elements present inside a frame?

driver.switchto().frame().

39)How do you come out of a frame?

driver.switchto().defaultContent().

40)How do you switch to the parent frame?

driver.switchto().parentframe().

41)How do you scroll a page in selenium?

We can use Java Script to scroll down the page in selenium. The java script to scroll down the page in selenium is Window.ScrollBy(0, 250). To execute the java script inside the java program we can help of executescript() which is available in javascriptExecutor interface.

42)How will you take a screenshot in selenium?

File src=((TakesScreenShot)driver).getScreenShotAS(output.FILE);

43)How do you get cell value from an Excel?

1. Get the excel file as an input.
2.Convert the excel file to a workbook (Get the workbook object or create the workbook object) from the Excel file.
3.Go to a particular sheet of the Excel (Get the sheet object from the workbook).
4.Go to a particular row in the sheet (Get the row object from the sheet).
5.Go to a particular cell in the row (Get the cell object from the row).
6.Get the data from the cell depending on the type of data.

44)Can you write a piece of code which will get multiple sets of data from Excel and login to the application?

driver.get("https://demo.actitime.com/login.do");
for (int i = 1; i <=4; i++) {
String un=xlib.getExcelData("Sheet1", i, 0);
String pw=xlib.getExcelData("Sheet1", i, 1);
driver.findElement(By.id("username")).sendKeys(un);
driver.findElement(By.name("pwd")).sendKeys(pw);
driver.findElement(By.id("loginButton")).click();

45)Can you tell me some annotations used in Test NG?

i)@Test ii)@BeforeMethod
iii)@AfterMethod
iv)@BeforeClass
v)@AfterClass

46)How do you ignore a test method in Test NG?

By using (enabled=false) we ignore a test method in the TestNG.

47)How do you skip a test method in Test NG?

If we set a test method to depend on other test method and if the assertion fails, the dependent test method will be skipped. dependsOnMethod().

48)What is the difference between ignore and skip?

Does that ignore is to deliberately pay no attention to while skip is to move by hopping on alternate feet.

49)How do you achieve test sequence execution in Test NG?

By using priority and dependsOnMethods we achieve testSequence.

50)Where you have used method overloading in web driver?

In driver.switchto().frame() we used overloaded methods.

51)What is the difference between driver.close() and driver.quit().

Driver.close(); closes the particular tab. driver.quit() close the entire browser. (Or) driver. quit () is used to exit the browser, end the session, tabs, pop-ups etc. But when you use driver. close (), only the window that has focus is closed.

52)What is the difference between cssSelector and Xpath?

CssSlector: Css selectors can be used to identify the elements which do not have id or name property and they are not links.
Css selectors use the HTML tag properties and values of the element to identify the element.
We can use any property value pair to identify the element. To evaluate the Css expression, we can use the tool called firepath which is an add-on for the firefox and an extension for firebug.
Xpath: To identify any elements in the web page, we can use Xpath expression.

53) What are the drawbacks with Absolute Xpath?

In future any changes in html page we cannot use absolute xpath. That is why we are using Relative Xpath.