You could implement your own expected condition. The following works
html/js:
<html>
<head>
<script type="text/javascript" >
window.onload = function(){
document.getElementById("string").value = "hello";
};
</script>
</head>
<body>
<input id="string" type="text" value="">
</body>
</html>
python:
import re
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import StaleElementReferenceException
from selenium.webdriver.support import expected_conditions as EC
class regex_to_be_present_in_element_value(object):
def __init__(self, locator, regex):
self.locator = locator
self.regex = regex
def __call__(self, driver):
try:
element_text = EC._find_element(driver,
self.locator).get_attribute("value")
if element_text:
return re.match(self.regex, element_text)
else:
return False
except StaleElementReferenceException:
return False
driver = webdriver.Firefox()
driver.get("file:///path/to/the/htmlfile.html")
try:
element = WebDriverWait(driver, 10).until(
regex_to_be_present_in_element_value((By.ID, "string"), "he*")
)
finally:
driver.quit()
It simply waits until there is text in the value attribute of the specified element matching the regex generated by the regex string passed to the constructor, in this case simply "hello". "he*" matches "hello".
I used this as a guide in making the class: https://selenium.googlecode.com/git/docs/api/py/_modules/selenium/webdriver/support/expected_conditions.html#text_to_be_present_in_element_value