# Selenium Interview Questions | Page 2

##### Question 11:How to set a value in textbox using Selenium?

Use the following code to set the value in the text box.

WebElement element = driver.findElement(By.id(“elementId”));
element.sendKeys(“Value”);
##### Question 12:How to clear a particular textbox using Selenium?

Use following code to clear text box values.

WebElement element = driver.findElement(By.id(“elementId”));
element.clear();

Note: findElement() is used to search an element in current page matching to the specified value. We can identify the element by id or by name.

##### Question 13:How to select drop down value using selenium?

Use the following code to select a value in dropdown control.

Select dropDown = new Select(driver.findElement(By.id(”drop_down_id”)));

Select By VisibleText:

dropDown.selectByVisibleText(“Text”);

Select By Index:

dropDown.selectByIndex(1);

Select By Value:

dropDown.selectByValue(“Value”);
##### Question 14:How will you find that an element in displayed on the screen?

Web Driver provides the methods to check the visibility of the web elements. These can be button, checkboxes, labels, radio buttons etc.

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

Syntax:-

isDisplyed():

Boolean isDiplayed = driver.findElement(By.id(“item_id”)).isDisplyed();

isSelected():

Boolean isSelected = driver.findElement(By.id(“item_id”)).isSelected();

isEnabled():

Boolean isEnabled = driver.findElement(By.id(“item_id”)).isEnabled();

Use below code to click on the hyperlink.

Driver.findElement(By.linkText(“www.modernpathshala.com”)).click();

##### Question 16:What is the difference between Single Slash “/” and Double Slash “//”?

Single Slash(/):

It starts the selection from document node and allows you to create absolute path expressions.

e.g. "/html/body/a" matches all the a tag elements.

Double Slash(//):

It starts the selection matching anywhere in the document and allows you to create relative path expressions.

e.g. "//a" matches all the a tag elements.

##### Question 17:How can we get a text of a web element?

Get command is used to get the inner text of the specified web element and its return string value.

String value = driver.findElement(By.id(“Input_Field_Id”)).getText();
##### Question 18:What is the difference between verify and assert commands?

Verify: Verify command checks whether an element is on the page or not, If it is not then the test will carry on executing. In verification, all the commands are going to run guaranteed even if any of tests fails.

Assert: Assert allows checking whether an element is on the page or not. The test will stop on step failed, If the asserted element is not available. In other words, the test will terminated at the point where check fails.

##### Question 19:What are the parameter you have to pass in Selenium?

The parameters which have to be passed in Selenium are listed below

1. Host
2. Port Number
3. Browser
4. URL
##### Question 20:What is the difference between sleep() and setSleep() methods?

Both are used to delay the speed of execution.

Sleep(): It suspends the current java thread for specified period of time. But one Thread.sleep() will set up wait only once. It takes the single argument in integer format.

Syntax: Thread.sleep(3000) – It will wait for 3 seconds.

Example: Suppose we have 3 selenium operations.

Operation1

Operation2

Operation3

If we want to set delay time 3000 milliseconds for each of these. It’s will be done as-

Operation1

Operation2

Operation3

SetSpeed(): It stops the execution for every selenium command for a specific amount of time. It takes single argument.

Syntax: selenium.setSpeed("3000");

Example: Suppose we have 3 selenium operations.

Operation1

Operation2

Operation3

We want to set delay time 3000 for each of these. It will be done as:-

selenium.setSpeed("3000");

Operation1

Operation2

Operation3

Share interview questions