Selenium Interview Questions and Answers Set 7

61. What is Same origin policy and how it can be handled?

The problem of same origin policy disallows to access the DOM of a document from an origin that is different from the origin we are trying to access the document.

Origin is a sequential combination of scheme, host and port of the URL. For example, for a URL http://, the origin is a combination of http,, 80 correspondingly.

Thus the Selenium Core (JavaScript Program) cannot access the elements from an origin that is different from where it was launched. For Example, if I have launched the JavaScript Program from “”, then I would be able to access the pages within the same domain such as “” or “”. The other domains like, would no more be accessible.

So, In order to handle same origin policy, Selenium Remote Control was introduced. 

62. When should I use Selenium Grid?

Selenium Grid can be used to execute same or different test scripts on multiple platforms and browsers concurrently so as to achieve distributed test execution, testing under different environments and saving execution time remarkably. 

63. What do we mean by Selenium 1 and Selenium 2?

Selenium RC and WebDriver, in a combination are popularly known as Selenium 2. Selenium RC alone is also referred as Selenium 1. 

64. Which is the latest Selenium tool?


65. How do I launch the browser using WebDriver?

The following syntax can be used to launch Browser:
WebDriver driver = new FirefoxDriver();
WebDriver driver = new ChromeDriver();
WebDriver driver = new InternetExplorerDriver(); 

66. What are the different types of Drivers available in WebDriver?

The different drivers available in WebDriver are:
• FirefoxDriver
• InternetExplorerDriver
• ChromeDriver
• SafariDriver
• OperaDriver
• AndroidDriver
• IPhoneDriver
• HtmlUnitDriver 

67. What are the different types of waits available in WebDriver?

There are two types of waits available in WebDriver:

• Implicit Wait
• Explicit Wait

Implicit Wait: Implicit waits are used to provide a default waiting time (say 30 seconds) between each consecutive test step/command across the entire test script. Thus, subsequent test step would only execute when the 30 seconds have elapsed after executing the previous test step/command.

Explicit Wait: Explicit waits are used to halt the execution till the time a particular condition is met or the maximum time has elapsed. Unlike Implicit waits, explicit waits are applied for a particular instance only. 

68. How to type in a textbox using Selenium?

User can use sendKeys(“String to be entered”) to enter the string in the textbox.
WebElement username = drv.findElement(“Email”));
// entering username

69. How can you find if an element in displayed on the screen?

WebDriver facilitates the user with the following methods to check the visibility of the web elements. These web elements can be buttons, drop boxes, checkboxes, radio buttons, labels etc.

• isDisplayed()
• isSelected()
• isEnabled()

boolean buttonPresence = driver.findElement(“gbqfba”)).isDisplayed();
boolean buttonSelected = driver.findElement(“gbqfba”)).isDisplayed();
boolean searchIconEnabled = driver.findElement(“gbqfb”)).isEnabled(); 

70. How can we get a text of a web element?

Get command is used to retrieve the inner text of the specified web element. The command doesn’t require any parameter but returns a string value. It is also one of the extensively used commands for verification of messages, labels, errors etc displayed on the web pages.
String Text = driver.findElement(“Text”)).getText();