1

Is it possible to reparse the page using selenium? I click a button using the function then the HTML changes because of javascript and I want to reparse the page, not refresh it.

The methods of get/refresh cause the page to reload which isn't what I'm looking for.

Crizly
  • 971
  • 1
  • 12
  • 33

1 Answers1

2

It is not exactly "reparsing" actually. From what I understand this is about detecting the changes made on the page. For that, you should use WebDriverWait and a set of built-in expected conditions (or you can write a custom one) to wait for that change to be made on the page.

Let's say, for instance, an element is added to the page when you click the button. Here is how to wait until this element is visible:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# ...

button.click()

wait = WebDriverWait(driver, 10)
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "#id-of-the-added-element")))

# now the page is "re-parsed"
print(driver.page_source)

It would wait up to 10 seconds checking the state of the expected condition every 500 milliseconds (by default).

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195