I have a container, which contains number of elements. I am looping thru the elements. My question is what is the syntax for checking if the element is not clickable.
7 Answers
The existing methods, isDisplayed and isEnabled cannot check for whether the element is clickable or not.
If you want to wait for element till it is clickable and then click it, you may like to look this: Selenium WebDriver - determine if element is clickable (i.e. not obscured by dojo modal lightbox)
Actually, it may be difficult to check whether the element is clickable or not without actually clicking it.
2 Comments
You can try the following if else condition
if(driver.findElement(By.xpath("--xpath of the clickable content")).isEnabled())
{
System.out.println("Element is clickable");
}
else
{
System.out.println("Element is not clickable");
}
2 Comments
One option is to do the following.
from selenium.common.exceptions import WebDriverException
try:
element.click()
# add to list of clickable elements
except WebDriverException:
print "Element is not clickable"
1 Comment
try:
WebDriverWait(driver, 1).until(EC.element_to_be_clickable(loc))
except:
# not clickable
else:
# clickable
1 Comment
You can create a custom keyword for it, but if element is displayed and enabled is required, but it's not all the conditions that make element clickable.
Example of custom keyword in custom lib:
from selenium.webdriver.remote.webelement import WebElement as webelement
def web_element_is_clickable(self, webelement):
return webelement.is_displayed() and webelement.is_enabled()
1 Comment
desplegar = bot.find_element_by_xpath('//*[@id="login-button"]')
try:
if desplegar.is_enabled:
desplegar.click()
else:
break
except:
desplegar = None