Selenium Interview Questions Part 2

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.


11) What is assertions and its types in selenium?

Assertion is used as verification points. It validates the actual state of the application against what is expected. There are 3 types of assertions.

  • Assert
  • Verify
  • Waitfor

12) What is the difference between assert and verify?

Assert: Assert command checks whether the given condition is true or false in the program. Suppose, we need to verify that a particular element is present in the application or not. Assert is used to verify that condition. If condition is true, it validate and continues to execute the rest of the program but if condition is false, execution will be halted and no further steps will be executed.

Verify: Verify command also checks whether the given condition is true or false. Irrespective of the condition being true or false, the program execution doesn’t halts. You can utilize this to log the verification, but it continues with rest of the execution.

13) Which is the best way to locate an element?

Finding elements by ID is usually going to be the fastest option, because at its root, it eventually calls down to document.getElementById(), which is optimized by many browsers.

14) How do you launch the browser in Selenium?

We can launch the browser in the following ways.

WebDriver driver = new FirefoxDriver();
WebDriver driver = new ChromeDriver();
WebDriver driver = new InternetExplorerDriver();

15) Why do we assign Firefox driver to WebDriver interface instance?

    WebDriver driver = new FireFoxDriver();

WebDriver is an interface. If we create object with WebDriver instance, then it would be easy to change it other browser drivers like ChromeDriver etc.

We can also create object by using below statement.

FireFoxDriver driver = new FireFoxDriver();

But suppose, we need to change it chrome browser at any point in the program then we have to create object of chromedriver class and its not a good practice to create objects of several classes.

ChromeDriver driver = new ChromeDriver();

If we assigned it with WebDriver instance like below. Then WebDriver instance will be create only once and it will easy to change it another browser driver at any point in the program.

WebDriver driver; // it is created only one time in the program

driver = new FireFoxDriver();// any where in the program

driver = new CromeDriver(); // any where in the program

16)  What is the difference between “GET” and “NAVIGATE” to open a web page in selenium  web driver?

The ‘get’ method is only used to load a webpage, where ‘Navigate’ method will guide through the history like  back, forward and refresh etc. For more details, read this post.

17) What is the difference between findElement() and findElements() method?

findElement():  is used to find a particular element in a webpage using any locator like id , name etc.

findElements(): is used to find a list of elements of same type in a page.

For more details, read this post..

18) What is the difference between driver.Close() and driver.Quit () method?

close(): It will close the only current instance of browser.

Quit(): It will close all  instances of browser opened by selenium webdriver.

For more details, read this post..

19) How to refresh a page without using context click?

There are following ways, we can do this.

Using sendKeys.Keys method: 

In example, we are opening gmail and setting username as ‘testingpool.com’. When it send the keys (F5), page will be refreshed and username value will be removed.

		
driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.get("http://gmail.com");
driver.findElement(By.xpath("//*[@id='Email']")).sendKeys("testingpool.com");
driver.findElement(By.xpath("//*[@id='Email']")).sendKeys(Keys.F5);

Using navigate.refresh() method:

driver.get("https://testingpool.com");
driver.navigate().refresh();

Using navigate.to() method:

driver.get("https://testingpool.com");
driver.navigate().to(driver.getCurrentUrl());

Using get() method:

driver.get("https://testingpool.com");
driver.get(driver.getCurrentUrl());

Using ASCII code of F5:

driver.findElement(By.xpath("//*[@id='Email']")).sendKeys("testingpool.com");
driver.findElement(By.xpath("//*[@id='Email']")).sendKeys("\uE035");

20) How to maximize the browser window?

driver.manage().window().maximize();

 

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...