How to wait and get value of Span object in Selenium Python binding How to wait and get value of Span object in Selenium Python binding selenium selenium

How to wait and get value of Span object in Selenium Python binding


Correct way it this case would be to use Explicit waits (see Python code there). So you need something like

from selenium.webdriver.support import expected_conditions as ECwait = WebDriverWait(driver, 10)element = wait.until(EC.text_to_be_present_in_element((By.Id,'f_name'), 'Anuja'))


here's a function that does that;

def wait_on_element_text(self, by_type, element, text):        WebDriverWait(self.driver, 10).until(            ec.text_to_be_present_in_element(                (by_type, element), text)        )

Where by_type replace with e.g. By.XPATH, By.CSS_SELECTOR .Where element replace with the element path - the elements xpath, unique selector, id etc.Where text replace with the element's text e.g. the string associated with the element.


url = "http://..."driver = webdriver.Firefox()driver.get(url)wait = WebDriverWait(driver, 10)try:    present = wait.until(EC.text_to_be_present_in_element((By.CLASS_NAME, "myclassname"), "valueyouwanttomatch"))    elem = driver.find_element_by_class_name("myclassname")    print elem.textfinally:driver.quit()

I realized that the return object of wait.until is not an elem but a boolean variable, so I have to recall the locate element again.