There is a div that is always present on the page but doesn't contain anything until a button is pressed.
Is there a way to wait until the div contains text, when it didn't before, and then get the text?
Python selenium wait until element has text (when it didn't before)
608 Views Asked by NFeruch - FreePalestine At
2
There are 2 best solutions below
0
Michael
On
You could create your own custom expected condition that check for change in the text of the div
class DivTextToChange:
current_text = ''
def __call__(self, driver):
elem = driver.find_element(By.XPATH, "/html/xpath/to/div")
if elem:
text = elem.get_attribute('innerText')
if text and text != DivTextToChange.current_text:
DivTextToChange.current_text = text
return text
return False
to use:
text = WebDriverWait(driver, timeout=30).until(DivTextToChange())
Related Questions in PYTHON
- How to store a date/time in sqlite (or something similar to a date)
- Instagrapi recently showing HTTPError and UnknownError
- How to Retrieve Data from an MySQL Database and Display it in a GUI?
- How to create a regular expression to partition a string that terminates in either ": 45" or ",", without the ": "
- Python Geopandas unable to convert latitude longitude to points
- Influence of Unused FFN on Model Accuracy in PyTorch
- Seeking Python Libraries for Removing Extraneous Characters and Spaces in Text
- Writes to child subprocess.Popen.stdin don't work from within process group?
- Conda has two different python binarys (python and python3) with the same version for a single environment. Why?
- Problem with add new attribute in table with BOTO3 on python
- Can't install packages in python conda environment
- Setting diagonal of a matrix to zero
- List of numbers converted to list of strings to iterate over it. But receiving TypeError messages
- Basic Python Question: Shortening If Statements
- Python and regex, can't understand why some words are left out of the match
Related Questions in SELENIUM
- Can't get Selenium element
- Trying to find HREF from table with Selenium in Python
- Python | How i get the link of products that doesn't have href with selenium
- Selenium works only when I'm connected to a remote server
- Logging in automation using Selenium requests / responses- why it wont work?
- Why can't I scrape data from etherscan
- TypeError: 'SwitchTo' object is not callable
- Why driver.get doesn't work in Python Selenium when using Profile
- Trying to fill out an online form using selenium but it can't find the element
- Targeting Accept Policy With Selenium
- Python Selenium - Select Options not returning all the options
- Spraping data from a table is slow but uncertain why
- Unable to convert byte[] image to base64 using cucumber scenario api's - java selenium
- Selenium WebDriver - google account login problem using python
- Click on login button using Selenium
Related Questions in XPATH
- How can I load all the elements of a webpage with Selenium?
- Why is the copied XPATH not working for selenium?
- When I'm typing an Xpath or CSS selector in the console why won't matching results appear while typing? Results only appear after pressing Enter
- Nokogiri only returning 5 results
- XPath - how to exclude text from child node
- xpath issue in nested div
- Question using XPath to look for a sibling of a td with a certain name
- How to separate XML tags in freemarker in body function
- Wait using Path (Puppeteer)
- why can't I retrieve the track of my Spotify playlist even i have given correct full xpath
- How do I click the correct link based on text contained in another element using Selenium + Python?
- PHP DOMDocument ignores first table's closing tag
- String tokenise an xpath expression
- Problem to get into the next page, Selenium
- Scrapy / extracting data across multiple HTML tags
Related Questions in WEBDRIVERWAIT
- Unable to click the Explore text in Google Trends site using Selenium Python
- Selenium Explicit Wait fails to wait for clickability
- Not able to user WebDriverWait class
- How to apply Wait strategy in case it's not working always?
- Selenium Python Trying to Better Understand WebDriverWait and Splash/Transition Screens
- Selenium webdriver skipping some links while iterating through df - python
- Selenium Issues With Waiting Until Multiple Dropdowns Populate
- Python Selenium submit works only in debug mode
- How to replace Thread.sleep with WebDriverWait to avoid StaleElementReferenceException
- How to find the correct wait command for a dynamic table element?
- Using WebDriverWait to only check till timeout, without exception
- Issue selecting button tag with text using Selenium WebDriverWait
- Is there a way in python selenium to stop the script until a captcha is completed?
- In any scenario in automation where implicit wait will fail every time but explicit wait will pass even both having 10 sec default Time?
- Selenium - Unable to click on Navbar dropdown
Related Questions in EXPECTED-CONDITION
- error: expected unqualified-id before ‘)’ when I compile a c++ project
- How to click on a button element using a Python bot
- wait_for_non_empty_text() under Selenium 4
- How to click on a button continuously until another element appears using Selenium Python?
- How to make sure that a web element is completely loaded and ready with selenium expected_conditions
- Selenium *appears* to be ignoring waits and running over itself
- Selenium: 'function' object has no attribute 'click'
- Python selenium wait until element has text (when it didn't before)
- Waiting for elements to become interactible reliably
- Measure the time page element is visible on the page with selenium
- Selenium Webdriver Java with TestNG & POM: Should we use explicit wait (ExpectedConditions) for all the web elements
- Selenium Webdriver in Python- using expected_conditions.element_to_be_clickable with Webelement as parameter
- Is there any way in cypress to wait for multiple expected conditions
- Why getting panic in Rust program with an expect
- javascript error: Right-hand side of 'instanceof' is not an object error using expected_conditions with Selenium Python
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
WebDriverWaitexpected_conditionsprovidestext_to_be_present_in_elementcondition for that.The syntax is as following:
Afte using the following imports and initializations:
Used here locator
By.ID, "modalUserEmail"is for example only. You will need to use proper locator matching relevant web element.UPD
In case that element has no text content before the action and will have some text content you can wait for the following XPath condition:
//div[@class='unique_class']here is unique locator for that element and[text()]means that element has some text content.UPD2
If you want to get the text in that element you can apply
.texton the returned web element. Also, in this case it is better to usevisibility_of_element_located, not justpresence_of_element_located, so your code can be as following: