Get current HTML of rendered page using Selenium

对着背影说爱祢 提交于 2021-01-28 09:21:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!