Protractor Tricky Questions

How do you check whether an element enabled or not ?, condition: there is no such attribute as "disabled" in the element ?

Explanation : When there is no such attribute as disabled in element, the isEnabled() method from selenium does not work.

Solution : There is some attribute which makes the element to be disabled so we have to find the element and get the attribute using getAttribute() method then compare what is the value for enabled and disabled. BAsed on this we can conclude whether the element is enabled or not.

Is it possible to automate captcha ?

Yes, we can automate the captcha but there is a limitation that we can automate our own captcha but not others'

For example, a company has captcha in their website, so somebody has to check it but same time it is not possible for manual tester to check all the captcha's.

So we have to automate the captcha in dev/qa environment by getting the captcha answer in some attribute of the element, so based on that attribute we can enter the value to the text bar which accepts captcha value.

We should remove this attribute while pushing the code to Live environment.

Test case 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 protractor.
  • If you closed a hidden division pop up, and tried to perform action, then there is a chance that hidden division popup' animation wanot 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 Exception.


Step by step Solution :

  • First verify whether it is really any of the above scenario ?
  • Print number of element present that xpath using findElements method
  • If there is only one element please follow program 1, If there is more than 1 element follow program 2.


Program 1 : Using Explicit wait (Wait for the element to be visible):

  • Open the url (please change according to your application)
  • Create object for Explicit Wait set wait time as 60 seconds
  • Use visibilityOfElementLocated method present in Expected conditions class

Program 2 : Using findElements And IsDisplayed:

  • Open the url (please change according to your application)
  • Set implicitly wait for 1 minute
  • Find all the elements which matches the xpath and store them
  • iterate over the element we stored
  • verify if the element is displayed or not
  • Click element if displayed or ignore
  • Once element is clicked, break the loop
Do implicit wait has any impact on findElements ?

Most of the time implicit wait will not work with findElements but only when there is no element for the given locator then only implicit wait works from findElements.

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions

Protractor Training

new tutorial I am starting new Protractor training batch on Weekends. It is two days course from 01-june-2019 to 02-june-2019 based on class room (BANGALORE)

Interested people can confirm the seat by calling to +91 8971673487 or whatsapp to +91 9003381224

Find the course content : View Content