Selenium Interview Questions Part 3

In this selenium interview questions series, we will cover questions from basics to advance level which are mostly asked in companies interviews.You are also welcome to add questions faced by you in interviews. It may help some one. If you find any discrepancies in answers or have any suggestion , do let us know.

Note : You can add questions and answer in comments section after the post. We will add them to the series if not duplicated.


 

21) While using click command can we use screen coordinate? 

To click on specific part of element, we can use clickAT command.  ClickAt command accepts element locator and x, y co-ordinates as arguments.

e.g. clickAt (locator, cordString)

22) What are the different types of Drivers available in WebDriver?

There are following drivers available in webdriver.

  • FirefoxDriver
  • InternetExplorerDriver
  • ChromeDriver
  • SafariDriver
  • OperaDriver
  • AndroidDriver
  • IPhoneDriver
  • HtmlUnitDriver

23) How to type in a textbox using Selenium?

We use ‘sendkeys’ method to enter the data into a textbox as shown below.

driver.findElement(By.xpath(“//*[@id=’Email’]”)).sendKeys(“testingpool.com”);

24) What is same origin policy? How you can avoid same origin policy?

The “Same Origin Policy” is introduced for security reason, and it ensures that content of your site will never be accessible by a script from another site.  As per the policy, any code loaded within the browser can only operate within that website’s domain.

To avoid “Same Origin Policy” proxy injection method is used, in proxy injection mode the Selenium Server acts as a client configured HTTP proxy , which sits between the browser and application under test and then masks the AUT under a fictional URL.

25) What is the difference between implicit wait and explicit wait?

Implicit wait: Implicit wait is used to provide a default timeout through out the script. Suppose, you have defined 20 seconds as implicit wait. Now, program  control will wait for 20 seconds on each step and will move to next step only after 20 seconds has elapsed.

e.g. driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

Explicit wait: Explicit wait is applied for a particular element. It will wait until a specified condition is meet or maximum time has elapsed , before moving to next step in the program.

For more detail, read this post..

26) How can we get a text of a web element?

We can use method ‘gettext()’ to the retrieve the text of a particular element.

String strText = driver.findElement(By.id(“myid”)).getText();

27) What kind of navigation commands are available in selenium?

There are following type of navigation command available in selenium.

navigate().back() – helps user to go back into the browser history made during selenium session.

e.g.
driver.navigate().back();

navigate().forward() – helps user to go to next page into the browser history made during selenium session.

e.g. 
driver.navigate().forward();

navigate().refresh() – helps user to refresh the current web page.

e.g.
driver.navigate().refresh();

navigate().to() – helps user to launch a new web browser window and navigate to the specified URL.

e.g.
driver.navigate().to(“https://gmail.com”);

28) How to get the current url of a browser?

You can use the below method to get the current url.

driver.getCurrentUrl();

29) How to get the title of the browser opened by selenium?

You can use the below method to get the title.

driver.gettitle();

30) How to select value in a dropdown?

We have to use select class provided by selenium webdriver. We can select the values in the following ways as mentioned below.

selectByValue:

Select selectByValue = new Select(driver.findElement(By.id(“ID1”)));
selectByValue.selectByValue(“Jan”);

selectByVisibleText:

Select selectByVisibleText = new Select (driver.findElement(By.id(“ID1”)));
selectByVisibleText.selectByVisibleText(“January”);

selectByIndex:

Select selectByIndex = newSelect(driver.findElement(By.id(“ID1”)));
selectByIndex.selectByIndex(1);

Avatar photo

Shekhar Sharma

Shekhar Sharma is founder of testingpool.com. This website is his window to the world. He believes that ,"Knowledge increases by sharing but not by saving".

You may also like...