问题
I'm strugling to get the rendered html code in selenium of a facebook app. After login I go to the app page and use time.sleep(20)
to wait for it to fully render.
I have already tried 3 solutions none of witch works:
self.driver.page_source # This one returns source code
self.driver.find_element_by_xpath('//*').get_attribute('outerHTML')
self.driver.execute_script("return document.getElementsByTagName('html')[0].outerHTML")
I'm using the google chrome driver and python3. Just to be clear.
EDIT 1 :
I wasn't clear about what don't work means. Each one of the above returns a different thing from what is presented when I hit "Inspect Element"
回答1:
self.driver.find_element_by_xpath("//body").get_attribute('outerHTML')
...and don't use time.sleep(). Use a WebdriverWait and wait for a unique element on the page to load.
来源:https://stackoverflow.com/questions/48954847/get-current-html-of-rendered-page-using-selenium