How do I track dynamically updating code on a website?
On a website there is a part of the code that shows notifications. This code gets updates frequently, and I would like to use selenium to capture the changes.
Example:
# Setting up the driver
from selenium import webdriver
EXE_PATH = r'C:/Users/mrx/Downloads/chromedriver.exe'
driver = webdriver.Chrome(executable_path=EXE_PATH)
# Navigating to website and element of interest
driver.get('https://whateverwebsite.com/')
element = driver.find_element_by_id('changing-element')
# Printing source at time 1
element.get_attribute('innerHTML')
# Printing source at time 2
element.get_attribute('innerHTML')
The code returned for time 1 and time 2 is different. I could of cause capture this using some time of loop.
# While loop capturing changes
results=list()
while True:
print("New source")
source=element.get_attribute('innerHTML')
new_source=element.get_attribute('innerHTML')
results.append(source)
while source==new_source:
time.sleep(1)
Is there a smarter way to do this using selenium's event listener? new_source=element.get_attribute('innerHTML')