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.
Following should make it work -
element.is_displayed() and element.is_enabled()
This code is in Python. You can change it to the language of your choice.
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.
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");
}
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"
try:
WebDriverWait(driver, 1).until(EC.element_to_be_clickable(loc))
except:
# not clickable
else:
# clickable
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()
desplegar = bot.find_element_by_xpath('//*[@id="login-button"]')
try:
if desplegar.is_enabled:
desplegar.click()
else:
break
except:
desplegar = None
© 2022 - 2024 — McMap. All rights reserved.