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 HandsMay 12, 2015 at 11:09
-
1No, every enable element is not clickable say example after login Hello text is there even it is is enabled but it is not clickable– QAMemberMay 12, 2015 at 11:25
-
2So you want to know which elements are links or buttons? Or more general: Which elements trigger an action after you clicked it?– TwaldigasMay 12, 2015 at 11:35
-
if element is not clickable then no need to check for click I think..– Helping HandsMay 12, 2015 at 11:39
-
1Your 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 MonicaMay 12, 2015 at 13:47
4 Answers
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.– QAMemberMay 12, 2015 at 12:07
-
-
everything can be clicked but some of them only having actions to perform by clicking . I want to find that elements– QAMemberMay 12, 2015 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. May 12, 2015 at 12:43
-
2+1. Most frustrating is situation when OP is so beginner s/he does not understand when answer is correct. May 12, 2015 at 13:43
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.
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:
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.