3

My Question is How to check whether the element is clickable or not ?.Is there any method to chat that like isElementVisible() or IsElementPresent() and etc ... Please let me know if one is having a knowledge about this problem. My scripting language is javascript+Node.js and using selenium webdriver

  • Enabled means it is clickable. – Helping Hands May 12 '15 at 11:09
  • 1
    No, every enable element is not clickable say example after login Hello text is there even it is is enabled but it is not clickable – QAMember May 12 '15 at 11:25
  • 2
    So you want to know which elements are links or buttons? Or more general: Which elements trigger an action after you clicked it? – Twaldigas May 12 '15 at 11:35
  • if element is not clickable then no need to check for click I think.. – Helping Hands May 12 '15 at 11:39
  • 1
    Your test should not simulate mad monkey clicking on anything clickable. How would you know if result is correct? Instead, it should click on known elements, and confirm desired result of that action. @Yamikuronue has your correct answer, if you understand what automated testing is. – Peter M. - stands for Monica May 12 '15 at 13:47
4

You can click text. It just (usually) doesn't DO anything. Everything that exists CAN be clicked -- you can move your pointer over it and click the mouse. Whether the application does anything with that click event is up to the logic behind the page, which Selenium can't help you with because it doesn't know how your application works.

An example with clickable text: https://jsfiddle.net/xqnxkhuw/ (click the words in the lower-right panel to see it in action)

So what you're after is really domain knowledge, which we can't help you with.

  • Thanks for your answer @Yamikuronue, Here my goal is not clicking the text or button etc. I am trying to find whether element is clickable element or non-clickable element. – QAMember May 12 '15 at 12:07
  • But everything can be clicked. What do you mean by "clickable"? – Yamikuronue May 12 '15 at 12:14
  • everything can be clicked but some of them only having actions to perform by clicking . I want to find that elements – QAMember May 12 '15 at 12:37
  • Then my answer does apply. Webdriver has no idea what parts of your application ought to have interactions. That's domain knowledge. – Yamikuronue May 12 '15 at 12:43
  • 2
    +1. Most frustrating is situation when OP is so beginner s/he does not understand when answer is correct. – Peter M. - stands for Monica May 12 '15 at 13:43
3

I do this test as little different way.I am using exception of wait.You can also use more time for wait object.

//Code written in Java
public static boolean isClickable(WebElement webe)      
{
    try
    {
        WebDriverWait wait = new WebDriverWait(yourWebDriver, 5);
        wait.until(ExpectedConditions.elementToBeClickable(webe));
        return true;
    }
    catch (Exception e)
    {
        return false;
    }
}

Call this method in your class.

Example :

boolean bst = className.isClickable("your element");

If bst is true then element is clickable otherwise not.

1

This is only valid if Element has disabled property in HTML DOM.

You have to check whether the element has "disabled" attribute.

Read more on that here:

  • This only while you have disable attribute/Property in HTML code – Sagar007 Nov 19 '15 at 13:32
-2

First Solution : By default you cannot find the element is click able or not you must have to perform click action on that element and after clicking on the element check any unique locator after click event perform.

Second Solution : check the element tag name

String tagname=driver.findElement(By.id("id")).getTagName();

if it is button then check it's attribute is not disabled. then it is click able.

Not the answer you're looking for? Browse other questions tagged or ask your own question.