Perform A WebDriverWait() Or Similar Check On A Regular Expression In Python
I would like to be able to perform something similar to a WebDriverWait(), i.e: WebDriverWait(driver, 60).until( expected_conditions.text_to_be_present_in_element((By.XPATH, '
Solution 1:
If you look into what an "Expected Condition" is, you would find it easy to make a custom one:
import re
from selenium.webdriver.support.expected_conditions import _find_element
class text_match(object):
def __init__(self, locator, regexp):
self.locator = locator
self.regexp = regexp
def __call__(self, driver):
element_text = _find_element(driver, self.locator).text
return re.search(self.regexp, element_text)
Usage:
WebDriverWait(driver, 60).until(
text_match((By.XPATH, "//tr[5]/td[11]/div"), r"[0,1]{1}.[0-9]{6}")
)
Post a Comment for "Perform A WebDriverWait() Or Similar Check On A Regular Expression In Python"