Selenium Interview Question Part – 2

This is the second post in the series of selenium interview preparation. In this post also we are focusing on understanding basic selenium concepts. People with experience less than 3 years can expect this type of questions.

Ques 1 : What are two different methods to navigate to a particular url in a browser using Selenium WebDriver?

There are two methods to navigate to a particular url using selenium:

  • get(url)
Ques 2: How to send ENTER/TAB key in Selenium WebDriver?
Ques 3: List down methods for Alert Handling?

Following are the frequently used methods within an alert.

  • Accept an alert.
  • Reject an alert.
  • Get message from an alert.
Ques4: Difference type of wait statement in Selenium WebDriver?

In Selenium WebDriver, to sync up scripts there are three types of wait:

PageLoadTimeout – This is the maximum time selenium waits for a page to get load successfully on a browser. If the page takes more than this time, it will throw Timeout exception.

Implicit Wait – this wait can be considered as element detection timeout. Once defined in a script, this wait will be set for all the web elements on a page.

  • Selenium keeps polling to check whether that element is available to interact with or not.
  • This is the maximum time selenium wait to interact with that web element, before throwing “Element not found exception”.
Explicit Wait – This wait can be considered as conditional wait, and is applied to a particular Web Element with a condition. There are many conditions which can be applied using explicit wait.

  • Say, for example, there is a web element on a page which takes more than expected time to appear on the page, so instead of increasing Implicit wait for a particular Web Element we can apply explicit wait to that element with a condition.
You can learn more about waits from Wait commands in Selenium web driver.

Ques5: Difference between Absolute and Relative xpath?

  • Absolute xpath starts from starting of the page. As in an html page, the first tag is HTML.
  • “/” is used to access an immediate child of the parent tag.
  • Example: html/body/table/tbody/tr[2]/td/input
  • Relative xpath starts from anywhere on the page.
  • “//” is used to access any child of the parent tag.
  • Syntax: //htmlTagname[@attribute=’value’]
  • Example: //input[@type=’text’] – It represents xpath of a WebElement which is represented by tagname input and has an attribute type = ‘text’.

To learn more about writing xpaths. Please follow Mastering Xpath article.

Ques6: Write a code to get numbers of frames on a page?

  • To get the number of frames, we will call a method called findElements which will return all the frames elements in a list, and then find its size.
Ques7: How to scroll down a page using JavaScript in Selenium?

  • Scroll down operation can be performed by invoking JavaScript:
Ques8: How to get the colour of a text or a link text?

There is method element.getCssProperty(<property>) which returns the value of the css property you will pass as an argument. In case you need color property, pass the property as color.

Ques9: How to get the width of a textbox?

Ques10: How to take Screenshot in Selenium WebDriver?

  • To take a screenshot in Selenium there is a method called getScreenshotAs() from a class called TakesScreenshot.
Ques11: What is the basic syntax of xpath?

Basic syntax of relative xpath:

//Html Tagname[@attribute=’value’]

Ques12: What are different methods and axes in xpath?

  • Methods  in xpath – contains(), starts-with() and text().
  • Axes in xpath – following, preceding, following-sibling, preceding-sibling, parent, ancestor are some frequently used axes in xpath.

Ques13: How to set the size of Browser window using selenium? or how to test responsiveness  of an application?

  • To set the size of a window of a Browser, method used is setSize(dim);
Ques14: How to maximise a window of a Browser using selenium?
Ques15: How to get the color of a text on a page?
Ques16: Write a code to get the status of all the checkbox on a page?

  • isSelected() – method is used to verify whether a checkbox is selected or not.
  • It’s a boolean operation returns true if selected else false.
  • To verify all the checkbox, first, get all these checkboxes (by using findElements method) in a list and then iterate this list to get the status of each checkbox.
Ques17: Write a code to wait for a particular element to be visible on a page?

  • Explicit wait can be used to apply conditional wait (here, condition is visibility of an element on a page)
Ques18: Write a code to wait for a text to change its colour?

  • To apply a conditional wait on change of property(attribute) of a WebElement explicit wait can be used.
  • Here, the attribute will be color.
Ques19: Write a code to wait for an alert to appear?

  • Waiting for an alert to appear on a page can be performed using explicit wait in Selenium WebDriver.
Ques20: How to highlight a text or an image in selenium?

  • To highlight a text or an image in Selenium, JavaScript can be injected.


Soon we will be updating next series of Interview Questions. Till then Happy Learning 🙂

Saurabh Dhingra

About the Author

Saurabh Dhingra

Follow Saurabh Dhingra:

Leave a Comment: