Protractor Automation and Jasmine interview questions

How can we find all the links on a web page?

All the links are formed using anchor tag 'a' and all links will have href attribute with url value. So by locating elements of tagName 'a' we can find all the links on a webpage.

How to verify tooltip text using protractor?

Web elements have an attribute of type 'title'. By fetching the value of 'title' attribute we can verify the tooltip text in protractor.

What are the different mouse actions that can be performed?

1. click(element)
2. doubleClick(element)
3. contextClick(element)
4. mouseDown(element)
5. mouseUp(element)
6. mouseMove(element)
7. mouseMove(element, long xOffset, long yOffset)

Write a code to wait for an alert to appear?

Waiting for an alert to appear on a page can be performed using explicit wait in protractor.

browser.wait(ExpectedConditions.alertIsPresent(), 30000)

Write a code to wait for a particular element to be visible on a page using protractor ?

Visibility means that the element is not only displayed but also has a height and width that is greater than 0. You can use visibilityOf function to check the visibility of the element

let EC = ExpectedConditions;
let condition = EC.visibilityOf(element("hidden")))
browser.wait(condition, 30000)

Testcase failed saying "ElementNotVisible", but when analyzed manually element is visible ? How to Handle it ?

There are couple of things which may cause this issue.

  • Element may not be visible in automation due to the speed of selenium.
  • If you closed a hidden division pop up, and tried to perform action, then there is a chance that hidden division popup' animation went over which could cause this issue.
  • There is could be an another element which has same xpath or locator in some other page
  • Example : Consider you have a element which has xpath as //button[@id='abc'] on page X, by clicking some tab on xpage navigates the user to Y page, Now there is an element on Y page which have xpath same as //button[@id='abc']. But when you launch your application, application may be directly landed on page Y. So with this scenario, if you try to perform on element on Y page it could throw an Error.

Is there a way to do drag and drop in selenium?

You can perform drag and drop using the browser.action() in protractor

// perform drag and drop

Return Javascript execution result in protractor Jasmine?

We need to return from your javascript snippet to return a value, so: js.executeScript(“document.title᾿); will return null, but

js.executeScript(“return document.title᾿);
will return the title of the document.

Can Protractor handle windows based pop up?

Protractor is a web automation testing tool which supports only web application testing. Therefore, windows pop up cannot be handled using Protractor.

Read Handle alerts and popups

Return Javascript execution result ?

We need to return from your javascript snippet to return a value, so: browser.executeScript("document.title"); will return null, but: browser.executeScript("return document.title"); will return the title of the document.

Read JavaScript Executor methods in Protractor

Write a code to wait for a particular element to be visible on a page?

Explicit wait can be used to apply conditional wait (Expected condition is visibility of an element on a page)

			by.xpath("//input[@type='text']")), 30000);

Read Implicit and Explicit Waits in Protractor

Write a code to wait for an alert to appear in protractor?

Waiting for an alert to appear on a page can be performed using explicit wait in Selenium WebDriver.

browser.wait(ExpectedConditions.alertIsPresent(), 30000);

Read Implicit and Explicit Waits in Protractor

What are the advantages of Automation framework in Protractor ?

  • Re-usability of code
  • Maximum coverage
  • Recovery scenario
  • Low cost maintenance
  • Minimal manual intervention
  • Easy Reporting
  • Logging for debugging
  • Easy Coding

What is an XPath?

Xpath or XML path is a query language for selecting nodes from XML documents. XPath is one of the locators supported by Protractor.

Selenium webdriver supports only Xpath 1.0 ,selenium does not support Xpath 2.0, 3.0

How to fetch the current page URL in Protractor ?

Using getCurrentURL() command we can fetch the current page URL-

	console.log("Web page url is : " +url )

Read get Page Url and Title in protractor

How to verify tool tip text using protractor ?

Tool tips web elements have an attribute of type 'title'. By fetching the value of 'title' attribute we can verify the tool tip text in selenium.


Read WebElement get commands in Protractor

Is there a way to click hidden LINK in web driver?

var Block1 = element("element ID"));
JavascriptExecutor js1=(JavascriptExecutor)driver;

Read JavaScript Executor methods in Protractor

Suppose developer changed the existing image to new image with same xpath. Is test case pass or fail?


How to handle alerts and confirmation boxes.?

We can switch to the alert using switchTo().alert() method in protractor

let abc:Alert = browser.switchTo().alert();
// typescript assigns the type dynamically, so don't have to provide type explicitly
let abc = browser.switchTo().alert();

Read Handle javascript alerts in protractor jasmine

What is the order of fastest browser implementation for Protractor ?

HTMLUnitDriver is the fastest browser implementation as it does not involves interaction with a browser, This is followed by Firefox driver and then IE driver which is slower than FF driver and runs only on Windows.

How to get typed text from a textbox?

Use get Attribute ("value") method by passing arg as value, getAttribute() method will return a promise which contains string

element(by.xpath("xpath of box")).getAttribute ("value")).then(function(textValue){

What are the prerequisites to run Protractor?

JDK, WebDriver (selenium standalone jar file), browser, application to be tested.

What are the web page Elements in Web Applications?

Link Button Image, Image Link, Image Button Text box Edit Box Text Area Check box Radio Button Drop down box List box Combo box Web table /HTML table Frame

What is the difference between browser.close() and browser.quit() command?

close(): Protractor'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.

What is ElementFinder ?

The ElementFinder is nothing but elements present in the webpage, we will get this as result of element(by.locator("locator value"))

ElementFinder can be used to build a chain of locators that is used to find an element.

An ElementFinder does not actually attempt to find the element until an action is called, which means they can be set up in helper files before the page is available.

Read WebElement and Element finder in protractor

What is WebElement in Protractor?

When we perform any action on the ElementFinder, protractor converts it into WebElement and perform the operation.

We can convert the ElementFinder into WebElement using getWebElement() command present in the protractor. Every method calls this method internally before performing operation on the webpage object
// below code convert the Element finder to WebElement before performing
// click operation
// getWebElement

Read WebElement and Element finder in protractor

Check If An Element Exists in Protractor ?

Get the all the matches for that locator and the value should be more than 0 if it is zero then there no such element in the we page

You can use below protractor code snippet to check if a element with id 'element-id' exists on web page.

		console.log("element is present")
		console.log("element is not present")

How to disable a test case in Jasmine With Protractor ?

To disable the test case we use the make the it block in to xit block in jasmine

xit("test description)			

Read Disable a it blcok in Jasmine protractor

Explain what is Time-Out test in Protractor?

The Time-Out test in Protractor is nothing but time allotted to perform unit testing. If the unit test fails to finish in that specific time limit, protractor will abandon further testing and mark it as a failed.

How To Check If An Element Is Visible With Protractor?

We can use isDisplayed() method to check whether a element is visible or not. You can check whether an element is visible or not using below code.

		console.log("element is Visible")
		console.log("element is not visible")

Read Disable a it blcok in Jasmine protractor

How to wait for element to be available in angular applications ?

The application may load some elements late and your script needs to stop for the element to be available for next action.

In below protractor code, the script is going to wait maximum 30 seconds for the element to be available. Feel free to change the maximum number per your application needs.

browser.wait(ExpectedConditions.presenceOf(element("element-id"))), 30000)	

Read Implicit and Explicit Waits in Protractor

How to Focus On A Input Element On Page using protractor ?

Doing focus on any element can be easily done by clicking the mouse on the required element. However when you are using selenium you may need to use this workaround instead of mouse click you can send some empty keys to a element you want to focus.

let webElement  = element("element-id"));
//Send empty message to element for setting focus on it.

Read WebElement Commands in Protractor

How to Overwrite Current Input Value in editable field On Page using protractor ?

The sendKeys method on WebElement class will append the value to existing value of element. If you want to clear the old value. You can use clear() method.

let webElement = element("element-id"));
webElement.sendKeys("new input value");		

Read WebElement Commands in Protractor

How to Mouse over Action To Make Element Visible Then Click?

When you are dealing with highly interactive multi layered menu on a page you may find this useful. In this scenario, an element is not visible unless you click on the menu bar.

So below code snippet will accomplish two steps of opening a menu and selecting a menu item easily.


How to Extract CSS Attribute Of An Element in protractor ?

We can get any CSS property of a web element using grtCSSValue in protractor. For example, to get background color of an element use below snippet

	console.log("Font size is : " +fontSizeValue);

Read WebElement Commands in Protractor

Get Size of an Element in protractor ?

getSize() method present in protractor determines the size of an element, size consists of two values width and height which are sum of respective attributes

Width = margin-left + margin-right + padding-left + padding-right + actual width;

	console.log("Width of the element : "+elementSize.width);
	console.log("Height of the element : "+elementSize.height);

Read WebElement size in Protractor

How to check whether method is displayed in webpage or not ?

isDisplayed() method in Protractor verifies and returns a boolean value based on the state of the element whether it is displayed or not.

	console.log("Displayed flag is : "+displayFlag);

how to check whether whether element is enabled or not ?

isEnabled() method in Protractor verifies and returns a boolean value based on the state of the element whether it is enabled or not.

	console.log("Enabled flag is : "+enabledFlag);

Read WebElement States in Protractor

How to check whether a dropdown is selected or not in angular applications ?

For testing angular application, we would be using protractor browser automaton tool.

isSelected() verifies if an element is selected or not, isSelected() method returns boolean value, true if the element is selected and false if it is not.

element(by.xpath("//input[@id='selected'] [value='Bangalore']")).isSelected().then(function(selectedFlag){
	console.log("Is element selected : "+selectedFlag);

Read WebElement Selected or not in Protractor

How to Find All Links On The Page using protractor ?

A simple way to extract all links from a web page.

	console.log("Number of links in page  : " +allLinks);

How to Execute A JavaScript Statement On Page in protractor ?

If you love JavaScript, you are going to love this. browser.execute() can run any javascript code snippet on browser during your testing.

In case you are not able to find a way to do something using web driver, you can do that using JS easily.

browser.execute("javascript code");

Read JavaScript Executor methods in Protractor

How to Get HTML Source Of A Element On Page using Javascript in protractor ?

If you want to extract the HTML source of any element, you can do this by some simple Javascript code.

browser.executeScript("return document.getElementById('" + elementId + "').innerHTML;");

Read JavaScript Executor methods in Protractor

How To Switch Between Frames using Protractor?

Multiple iframes are very common in recent web applications. You can have your webdriver script switch between different iframes easily by below code sample


What is the difference between "GET" and "NAVIGATE" to open a web page in protractor ?

Get method will get a page to load or get page source or get text that's all whereas navigate will guide through the history like refresh, back, forward.

For example if we want to move forward and do some functionality and back to the home page this can be achieved through navigate() only.

browser.get() will wait till the whole page gets loaded and browser.navigate() will just redirect to that page and will not wait

Difference between flex and flash application.?

In flash there is no code just based on creativity(design) we will complete the work(time consuming process) whereas flex contain some small functions which is integrated with mxml,PHP..(no tool is there to develop flex we want to use the properties of css and style sheet)

How to stop Page Loading, when element is loaded ?

We can stop page loading by sending Keys.ESC to body element in protractor.


Why do we go for automation testing ?

  • Manual testing of all work flows, all fields, all negative scenarios is time and cost consuming.
  • It is difficult to test for multi lingual sites manually.
  • Automation does not require human intervention, We can run automated test unattended(nightly regressions).
  • Automation increases speed of test execution.
  • Automation helps increase test coverage.
  • Manual testing can become boring and hence error prone.

Intermediate level protractor interview questions

How do you accept alert in protractor ?

We can accept the alert using accept methods present in the Alerts class. But before accepting the alert we have to switch the control to the alert in protractor


Read Complete alerts handling methods

How do you cancel alert in protractor ?

To close or cancel the alert we have to switch to the alert using switchTo().alert() method and then we have to use dismiss() method to cancel the alert using protractor


How do you set value to prompt alert in protractor ?

we can use sendkeys method present in the alert class to set value in the p type of alert in protractor


Conf file related protractor interview questions

How do you execute a spec file both in chrome and firefox ?

We can execute same file in multiple browsers using the shardTestFiles , we have to set this parameter as false and we have to enable the chrome and firefox browsers in Multi-capabilities block.

shardTestFiles: false,
multiCapabilities: [{
  'browserName': 'chrome',
} , {
  'browserName': 'firefox',

Basic Protractor Interview Question

Can we set global variables in Protractor ?

we can set global variable in protractor using params present in the conf file.

Normally we set urls, usernames, passwords in this params

params: {
	login: {
	  email: 'default',
	  password: 'default'

what are the testing frameworks available for protractor ?

Jasmine : Jasmine is the most preferred test framework when Protractor is installed. We will use Jasmine in this article.

Mocha : Mocha is a JavaScript test framework which runs on Node.js. If you wish to use Mocha as your test framework, you will have to set it up with your Protractor

What is Jasmine ?

jasmine is javascript testing framework, we can use jasmine along with framework to test the web application.

It has features like beforeEach, afterEach, beforeAll, afterAll, it block and we can combine it blocks and describe blocks

How do you handle dropdowns in protractor ?

In selenium we have Select class to handle the dropdowns but in protractor doesnot have such helper classes.

To select a value in dropdown, we have to click the dropdown and then we should click the option inside the dropdown.

What is conf file ?

Conf file is the starting point of the protractor execution, conf file helps user to set the browser and pre-execution steps in protractor. We will configure grid details in protractor

How do you exclude a spec file in protractor ?

We can exclude test files using exclude parameter in conf.js file. Exclude parameter will be useful when you do not want to run only few tests or a folder.

Exclude also accepst Array as parameter values, also responds to regular expression.

										exclude: ['D:\\Protractor Demo\\specs\\dummytest.js']

How do you open firefox in protractor, which is installed in custom path ?

Sometimes the firefox might be installed in some custom path, in those cases firefoxPath in the conf.js file helps us to set the path to the firefox.exe file.

This woud be very useful if you are trying to perform version testing.

											firefoxPath: "C:/Program Files/Mozilla Firefox/Firefox 54/firefox.exe",

What is maxInstances in protractor ?

Maximum number of browser instances that can run in parallel for this set of capabilities. This is only needed if shardTestFiles is true in conf.js file

What is Typescript ?

Typescript is programming language, and it is supet set of Javascript. Typescript provides syntaxes like Java/Python but also it provides javascript function.

End of the day Typescript is converted into javascript and executed with protractor.

It is easy to learn typescript than javascript.

Why do we need protractor ?

What is directConnect in protractor conf.js file ?

directConnect is a conf.js file parameter, If true, Protractor will connect directly to the browser Drivers at the locations specified by chromeDriver and firefoxPath.

Only Chrome and Firefox are supported for direct connect.

											directConnect: false/true,

How do you set the geckodriver path in protractor ?

geckoDriver location is used to help find the geckodriver.exe file. This will be passed to the Selenium jar as the system property webdriver.gecko.driver.

If the value is not set when launching locally, it will use the default values downloaded from webdriver-manager.

											geckoDriver: 'D:/Eclipse progs/driverserver/geckodriver.exe',

Protractor Interview Questions

About Author

Myself KarthiQ, I am the author of this blog, I know ways to write a good article but some how I donot have the skills to make it to reach people, would you like help me to reach more people By sharing this Article in the social media.

Share this Article Facebook
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions
Copyright © CherCher Tech