I tried to create a function with custom wait condition in Python. However, I get an error:
TypeError: \'bool\' object is not callable
The wait.until(..)
function from selenium expects a function that it can call. However, you are, effectively, giving it a boolean.
element = wait.until(waittest(driver, '//div[@id="text"]', "myCSSClass", "false"))
Can be rewritten as:
value = waittest(driver, '//div[@id="text"]', "myCSSClass", "false")
element = wait.until(value)
Which makes this more clear - waittest returns a boolean, and wait.until(..)
tries to call it as a function - hence 'bool' object is not callable
.
You need to have your custom condition return a function that selenium can call to check if it's true yet. You can do this by defining a function inside your function:
def waittest(locator, attr, value):
def check_condition(driver):
element = driver.find_element_by_xpath(locator)
if element.get_attribute(attr) == value:
return element
else:
return False
return check_condition