Join us on :

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

Why do we write Webdriver driver = new FirefoxDriver(), why not SearchContext driver = new FirefoxDriver() ?

Don't hurry to answer like, Webdriver is interface and FirefoxDriver is Class. This is right but you need to understand the question first.

He is asking about SearchContext, which is parent interface of Webdriver, so the answer would be . Yes, we can write like that because SearchContext is parent of all the Interfaces and classes present in selenium.

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.

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 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 whth 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): 1. Open the url (please change according to your application).
2. Create object for WebdriverWait set wait time as 60 seconds.

                        		WebDriverWait wait = new WebDriverWait(driver, 60 /*seconds*/);

3. Use visibilityOfElementLocated method present in Expected conditions class


Complete Program 1 with Explicit wait (Wait for the element to be visible)


		// set the webdriver Wait as 60 seconds
		WebDriverWait wait = new WebDriverWait(driver, 60 /*seconds*/);
		String buttonXpath = "//button[@id='abc']";
		// wait for the element to be visible, max wait time is 60 seconds
		// clicks the button which has xpath = //button[@id='abc']

Program 2 : Using findElements And IsDisplayed:
1. Open the url (please change according to your application).
2. Set implicitly wait for 1 minute
3. Find all the elements which matches the xpath and store them 4. iterate over the element we stored 5. verify if the element is displayed or not
6. Click element if displayed or ignore
7. Once element is clicked, break the loop.

Complete Program 2 : findElements And IsDisplayed:

		// open webpage
		String buttonXpath = "//button[@id='abc']";
		// find all the elements with that xpath match
		List elements = driver.findElements(By.xpath(buttonXpath));
		// iterate over the elements
		for (WebElement webElement : elements) {
			// check whether element is displayed or not,
			if (webElement.isDisplayed()) {
				// if displayed click the element and 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.

About Author

Article is written by Pavan (a) KarthiQ. Well, I am serving notice period in an MNC, Bangalore. I thought to enrich every person knowledge a little, I always have a feeling, when we teach something, we will learn more than what you know. Knowledge is the only thing that doubles when you spend it.

I have also created the reporter for Protractor Jasmine. Use for your projects without any hesitation

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions
  • Piyush
    These questions and answers are really helpful and different from the ones which are available in other blogs..keep going your content is really helpful
  • Reply
  • Shiva
    Please add more tricky questions Kathik
    • karthiQ [ admin]
      We will add more questions on tricky interview question
  • Shiva
    Hi karthiQ, you are doing a great job man!
    • karthiQ [ admin]
      we are glad, it is useful to you
  • Riccha
    Hi KarthiQ,
    Content is very good in your website but many links are broken, Navigation is not proper.
    • karthiQ [ admin]
      Thanks Riccha,
      I have fixed half of the broken links, Please let me know more about navigation issue