Selenium Interview Question and Answers

 

Selenium Interview Question and Answers

Which framework you have worked on?

Explain each component you include in framework also why you use that component and what exactly the component is all about.

What is the main problem you have faced during your framework design?

The main challenge was to identify the proper structure of framework also to identify the right components which will fulfil your current requirement and future requirement.

Also, how to identify the libraries functions,

What source code management tool you have worked on?

We have used SVN for source code management tool.

How many team members are in automation testing?

We work in agile, and in my scrum team we have two QA engineers and our responsibility to perform functional testing, then we need to automation the required test cases.

How many browsers you have covered?

We do work on only two browsers i.e. Firefox and IE.

How did you manage to work on multiple browsers?

We used to trigger the script on multiple VM’s

How many scripts do you automate in a day?

IT can be 10, 20 and depends on the scenarios, see there are instance where for just one script whole day consume because for that test case we don’t have libraries present so it depends on the framework as well.

How many scripts you automated till date

I guess around 1000 or more than that.

Which execution engine you have used?

Selenium itself has no execution engine, however I have used TestNG as a execution engine.

Do you have experience in parallel testing?

Yes, I have designed a testNG framework with page object model with page factory approach we have design our script to run the parallel testing. Based on the thread count.

How did you execute failed test case only?

When we run test case using TestNG it self generate the failed test case report and we can use retry listener.

What is the super interface of WebDriver?

SearchContext.

Explain the architecture of selenium?

SearchContext is super most interfaces which are extended by WebDriver interface. Abstract methods of these two interfaces is implemented in Remote WebDriver class and overridden in respective browser classes such as FirefoxDriver, ChromeDriver, InternetExplorerDriver, SafariDriver etc.

 

 

 

 

 

 

 

 

 

 

Question: - What are locators ?

 

Answer: - Locators are used to identify the element.In Selenium before performing any action (click, type etc) we should find the element using locators. In Selenium there are 8 types are locators. All of them are static methods in By class (it is an abstract class).

 

o All the methods takes string as argument and it returns an object of type By.

o The By object is used as input argument for findElement() method.

 

o  Return type of findElement() method is WebElement (it is an Interface).

 

Question: - What do you understand by SYNCHRONIZATION?

Answer: - Process of matching Selenium speed with application is called as Synchronization. On real time applications when Selenium try to find the element it may through ‘NoSuchElementException’ even though specified locator is correct.

 

Synchronization can be achieved with the help of implicit and explicit wait.

How do you execute the exe file in selenium ?

In Selenium there is No option to run exe file. We can use runtime class to execute the exe files.

 

Example :-

 

Runtime.getRuntime().exec("C:/Windows/system32/calc.exe");

 

Write a script verify whether page is loaded within 3 seconds?

driver.manage().timeouts().pageLoadTimeout(3,TimeUnit.SECONDS);

when do we need to use java script in selenium ?

If the method of Selenium is not working such as sendkeys(), click() etc. then we can use javascript as alternative option. Ex: if the textbox is disabled we can use sendkeys() method. In such cases we can use javascript.

To run the Java Script in Selenium we should use executeScript() method

How do you handle context menu?

Ans: Right clicking is also called as Contextclick.

When we right click on any element we get list of options which is called as context menu.

To right click on the element we use contextClick() method of Actions class. and to select required option in the contextmenu, we press the shortcut such as "t" for new tab, "w" for newwindow etc using sendKey() method of Actions class.

 

When to use defaultContent() and parentFrame() method while working with frame.

In order to transfer the control back to the main page we can use the following statements:

Example: -  driver.switchTo().defaultContent();

In case of nested frames, to switch from child frame to parent frame we can use following statements;

 

Example: -  driver.switchTo().parentFrame();

 

 

 

What is the difference between implicit wait and explicit wait?

 

Implicit

Explicit

 

 

We do not specify the condition

We should specify the condition

 

 

We can handle ‘Findelement’ and ‘Findelements’

We can handle any method

 

 

After the duration we get ‘NoSuchElement’

After the duration we get ‘Timeout’

exception

Exception

 

 

Duration can be DAYS, HOURS, MINUTES,

Duration will be only Seconds

SECONDS etc.

 

 

 

 

 

What are the difference between findElement() and findElements()

 

findElement()

findElements()

 

 

 

 

Return type is WebElement

Return Type is List<WebElement>

 

 

 

 

If the specified locator is matching with

If the specified locator is matching with multiple

 

Multiple elements, it returns first matching

elements it returns all the matching elements.

 

element.

 

 

 

 

 

If the specified locator is not matching

If the specifies locator is not matching with any of

 

with any of the element then it will throw

the element it will not throw any exception

 

NoSuchElementException.

instead of this it returns empty list.

 

 

 

 

What is the difference between equals and == ?

 

Equals

==

 

 

 

 

It’s a method which is present in Object class.

This is a binary operator.

 

 

 

 

Equals method can be overloaded and logic to

Compare object can be changed based on the

Business rule.

Java doesn’t support operator overloading.

 

 

 

 

Equals method can be used only for Object comparision.

== operator is used for both primitive and objects.

 

Equals method is used for content comparison.

== Operator is meant for reference comparison and address comparison.

 

 

 

 

 

 

 

=====================================================================================

Question: - What is WebElement?

Answer: - WebElement represents an HTML element. HTML documents are made up by HTML elements. HTML elements are written with a start tag, with an end tag, with the content in between: <tagname> content </tagname>

 

 

Question: - What do you understand by xpath and type of xpath ?

Answer: - XPath is defined as XML path. It is a syntax or language for finding any element on the web page using XML path expression. XPath is used to find the location of any element on a webpage.

Basically there are two type of xpath we use.

1.           Absolute/Complete XPath.

2.           Relative/ Partial XPath

 

 

Question: - While using click command can you use screen coordinate?

Answer: - To click on specific part of element, you would need to use clickAT command.  ClickAt command accepts element locator and x, y co-ordinates as arguments- clickAt (locator, cordString)

=====================================================================================

Question: - Which attribute you should consider throughout the script in frame for “if no frame Id as well as no frame name”?

Answer: - We can use (driver.findElements(By.xpath(“//iframe”))).This will return list of frames. Now we will need to switch to every frame and search for locator which we want. Then break the loop.

 

Question: - Explain using Webdriver how you can perform double click ?

Answer: - We can perform double click by using

Syntax- Actions act = new Actions (driver);

act.doubleClick(webelement);

====================================================================================

 

Question: - What is the difference between getWindowhandles() and getwindowhandle() ?

Answer: - getwindowhandles(): It is used to get the address of all the open browser and its return type is iterator<String>

getwindowhandle(): It is used to get the address of the current browser where the control is and return type is string.

=====================================================================================

Question: - How can you check if a check-box or a radio button is selected?

Answer: - We can use the .isSelected() method, e.g.

driver.FindElement(By.id("id_of_checkbox")).isSelected();

====================================================================================

Question: - Is there a way to do drag and drop in selenium WebDriver?

Answer: - Yes, we can use the following code to do drag and drop

        Actions action = new Actions(driver);

        WebElement start = driver.findElement(By.cssSelector(“div.source”));

        WebElement end = driver.findElement(By.cssSelector(“div.target”));

        action.dragAndDrop(start,end).perform();

=====================================================================================

Question: - Give me the five different types of exceptions thrown in Selenium.

Answer: - List of few exception thrown by selenium

ü  NoSuchElementException

ü  StaleElementReferenceException

ü  ElementNotVisibleException

ü  TimeoutException

ü  ElementNotSelectableException

 

=====================================================================================

Question: - What is the use of the GetAttribute() method in Selenium?

Answer: - If we want to access the properties of a control or element such as id, name , class , Tagname etc, we use GetAttribute() method.

 

 

Question: - How to maximize window in Selenium ?

Answer: - After launching the browser, if we want to maximize the page we use the below code.

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

====================================================================================

Question: - How can we handle web based pop up?

Answer: - WebDriver offers the users with a very efficient way to handle these pop ups using Alert interface. There are the four methods that we would be using along with the Alert interface.

void dismiss() – The accept() method clicks on the “Cancel” button as soon as the pop up window appears.

void accept() – The accept() method clicks on the “Ok” button as soon as the pop up window appears.

String getText() – The getText() method returns the text displayed on the alert box.

void sendKeys(String stringToSend) – The sendKeys() method enters the specified string pattern into the alert box.

Syntax:

// accepting javascript alert

        Alert alert = driver.switchTo().alert();

              alert.accept();

===================================================================================

Question: - Explain how you can switch back from a frame?

Answer: - To switch back from a frame use method defaultContent()

Syntax-driver.switchTo().defaultContent();

 

====================================================================================

 

Question: - How to verify tooltip text using selenium?

Tooltips webelements have an attribute of type 'title'. By fetching the value of 'title' attribute we can verify the tooltip text in selenium.

String toolTipText = element.getAttribute("title");

=====================================================================================

Question: - How can we capture screenshots in selenium?

Answer: - Using getScreenshotAs method of TakesScreenshot interface we can take the screenshots in selenium.

File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

FileUtils.copyFile(scrFile, new File("D:\\testScreenShot.jpg"));

====================================================================================

Question: - How to check which option in the dropdown is selected?

Answer: - Using isSelected() method we can check the state of a dropdown's option.

Select countriesDropDown = new Select(driver.findElement(By.id("countries")));

dropdown.selectByVisibleText("India");

//returns true or false value                     

System.out.println(driver.findElement(By.id("India")).isSelected());

=====================================================================================

Question: - How to handle HTTPS website in selenium? or How to accept the SSL untrusted connection?

Answer: - Using profiles in firefox we can handle accept the SSL untrusted connection certificate. Profiles are basically set of user preferences stored in a file.

FirefoxProfile profile = new FirefoxProfile();

profile.setAcceptUntrustedCertificates(true);

profile.setAssumeUntrustedCertificateIssuer(false);

WebDriver driver = new FirefoxDriver(profile);

=====================================================================================

Question: - How to execute javascript in selenium?

JavaScript can be executed in selenium using JavaScriptExecuter. Sample code for javascript execution-

WebDriver driver = new FireFoxDriver();

if (driver instanceof JavascriptExecutor) {

              ((JavascriptExecutor)driver).executeScript("{JavaScript Code}");

}

 

==================================================================================

Question: - How to handle hidden elements in Selenium webDriver?

Using javaScript executor we can handle hidden elements-

(JavascriptExecutor(driver)) .executeScript("document.getElementsByClassName(ElementLocator).click();");

==================================================================================

Question: - What is Page Factory?

Answer: - Page factory is an implementation of Page Object Model in selenium. It provides @FindBy annotation to find web elements and PageFactory.initElements() method to initialize all web elements defined with @FindBy annotation.

public class SamplePage {

WebDriver driver;

@FindBy(id="search")

WebElement searchTextBox;

@FindBy(name="searchBtn")

WebElement searchButton;

//Constructor

public samplePage(WebDriver driver){

 this.driver = driver;

        //initElements method to initialize all elements

        PageFactory.initElements(driver, this);

    }

 //Sample method

    public void search(String searchTerm){

        searchTextBox.sendKeys(searchTerm); 

        searchButton.click();

    }

}

=====================================================================================

 

 

Question: - How do you simulate scroll down action?

Answer: - We can use java script to scroll down

avascriptExecutor jsx = (JavascriptExecutor)driver;

 jsx.executeScript("window.scrollBy(0,4500)", ""); // scroll down

 jsx.executeScript("window.scrollBy(450,0)", ""); //scroll up

  ex-

 public class ScrollDown {

  public static void main(String[] args) throws InterruptedException {

  WebDriver driver = new FirefoxDriver();

  driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

 driver.get("http://www.flipkart.com/womens-clothing/pr?sid=2oq,c1r&amp;otracker=hp_nmenu_sub_women_1_View%20all");

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

  JavascriptExecutor jsx = (JavascriptExecutor)driver;

  jsx.executeScript("window.scrollBy(0,4500)", ""); //scroll down

  Thread.sleep(3000);

  jsx.executeScript("window.scrollBy(450,0)", ""); //scroll up

 } }

=====================================================================================

Question: - How do u get the width of the textbox ?

Answer: -

driver.findElement(By.xpath(“xpath of textbox ”)).getSize().getWidth();

 driver.findElement(By.xpath(“xpath of textbox ”)).getSize().getHeight();

 

 

Question: - How can we locate an element by only partially matching its attributes value in Xpath?

Answer: - Using contains() method we can locate an element by partially matching its attribute's value. This is particularly helpful in the scenarios where the attributes have dynamic values with certain constant part.

xPath expression = //*[contains(@name,'user')]

The above statement will match the all the values of name attribute containing the word 'user' in them.

 

 

Question: - Explain how you can switch between frames?

Answer: - To switch between frames webdrivers [ driver.switchTo().frame() ] method takes one of the three possible arguments.

A number:  It selects the number by its (zero-based) index

A number or ID: Select a frame by its name or ID

Previously found WebElement: Using its previously located WebElement select a frame.

===================================================================================

Question: - What is the difference between driver.close() and driver.quit command?

Answer: - close(): WebDriver’s close() method closes the web browser window that the user is currently working on or we can also say the window that is being currently accessed by the WebDriver. The command neither requires any parameter nor does is return any value.

quit(): Unlike close() method, quit() method closes down all the windows that the program has opened. Same as close() method, the command neither requires any parameter nor does is return any value.

====================================================================================

Question: - Explain how you can use recovery scenario with Selenium?

Answer: - Recovery scenarios depends upon the programming language you use.  If you are using Java then you can use exception handling to overcome same.  By using “Try Catch Block” within your Selenium WebDriver Java tests

====================================================================================

Question: - How can you retrive the message in an alert box ?

Answer: - You can use the storeAlert command which will fetch the message of the alert pop up and store it in a variable.

====================================================================================

Question: - How can you find if an element in displayed on the screen?

Answer: - 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()

Syntax:

ü  isDisplayed():

o   boolean buttonPresence = driver.findElement(By.id(“gbqfba”)).isDisplayed();

ü  isSelected():

o   boolean buttonSelected = driver.findElement(By.id(“gbqfba”)).isDisplayed();

ü  isEnabled():

o   boolean searchIconEnabled = driver.findElement(By.id(“gbqfb”)).isEnabled();

====================================================================================

Question: - List the advantages of Web driver over Selenium Server?

Answer: - If we are using Selenium-WebDriver, we don’t need the Selenium Server as it is using totally different technology

Selenium Server provides Selenium RC functionality which is used for Selenium 1.0 backwards compatibility

Selenium Web driver makes direct calls to browser using each browsers native support for automation, while Selenium RC requires selenium server to inject Javascript into the browser.

=====================================================================================

What is the difference between Absolute/Complete XPath and Relative/ Partial XPath?

 

Absolute/Complete XPath

Relative/ Partial XPath

 

 

 

 

IThe key characteristic of XPath is that it begins with the single forward slash(/) ,which means you can select the element from the root node.

For Relative Xpath the path starts from the middle of the HTML DOM structure. Its start with the double forward slash (//), which means it can search the element anywhere at the webpage.

 

 

 

 

The disadvantage of the absolute XPath is that if there are any changes made in the path of the element then that XPath gets failed.

The disadvantage of the relative XPath is that if there are any changes made in the path of the element then that XPath gets failed but here change are less as compared to absolute xpath.

 

 

 

 

Equals method can be used only for Object comparision.

== operator is used for both primitive and objects.

 

Equals method is used for content comparison.

== Operator is meant for reference comparison and address comparison.

 

 

 

 

 

 

 

Question: - What are the different type of locaters are present in the selenium?

Answers: - In Selenium every object or control in a web page is referred as an elements, there are different ways to find an element in a web page they are

Ø  ID

Ø  Name

Ø  Tag

Ø  Attribute

Ø  CSS

Ø  Linktext

Ø  PartialLink Text

Ø  Xpath etc

 

Question: - What are the technical challenges with selenium.

Answers: - Selenium supports only web based applications

It does not support the Bitmap comparison

For any reporting related capabilities have to depend on third party tools

No vendor support for tool compared to commercial tools like HP UFT

As there is no object repository concept in Selenium, maintainability of objects becomes difficult

 

 

What is the difference between Assert and verify?

 

 

 

  1. Python said...

    wow interesting post thank you so much
    Python Online Training

Post a Comment