11

Can you illustrate the difference between text_to_be_present_in_element and text_to_be_present_in_element_value with an example, preferably in python ?

The following link seems to explain how text_to_be_present_in_element works but it's still unclear to me.

http://www.seleniumframework.com/python-basic/waits-and-synchronization/

Dhiwakar Ravikumar
  • 1,983
  • 2
  • 21
  • 36
  • Okay so there is an explanation here but it doesn't make things any clearer.https://seleniumhq.github.io/selenium/docs/api/dotnet/html/T_OpenQA_Selenium_Support_UI_ExpectedConditions.htm – Dhiwakar Ravikumar Jan 13 '19 at 09:41

1 Answers1

9

text_to_be_present_in_element is text value, to get the value with selenium element.text or Javascript element.textContent or element.innerTEXT

<p>this is text</p>

text_to_be_present_in_element_value is value attribute for element, to get the value with selenium element.get_attribute('value') and with JS element.getAttribute('value')

<input type="text" value="text value">
<input type="button" value="button text value">
ewwink
  • 18,382
  • 2
  • 44
  • 54
  • I'm waiting to see if a button element on my page whose text is "SAVE" appears on the page. The following syntax doesn't work as expected. save_button = WebDriverWait(chrome_browser, 60).until(EC.text_to_be_present_in_element(chrome_browser.find_elements_by_tag_name("button"),"SAVE")) print("SAVE BUTTON TEXT IS {}".format(save_button.text)) – Dhiwakar Ravikumar Jan 13 '19 at 10:36
  • try using `presence_of_element_located` or create new question with relevant html or URL – ewwink Jan 13 '19 at 10:56
  • 1
    `save_button = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '//button[text()="SAVE"]')))` for text and for value replace `text()` with `@value` – ewwink Jan 13 '19 at 11:02