Is it possible to get contents of iframe in selenium webdriver python?

☆樱花仙子☆ 提交于 2020-01-02 09:09:32

问题


In web testing, I plan to get contents of iframe(/htme/body/p), is it possible?

I use this method to set contents of iframe:

driver.switch_to_frame(driver.find_element_by_xpath("//iframe[contains(@title,'ALT')]"))
driver.switch_to_active_element()
time.sleep(1)
driver.execute_script(("document.body.innerHTML = '%s'" % recurWorkflowTestData["inputEditor"][inputNotes]))

time.sleep(1)
driver.switch_to_default_content()

回答1:


To follow the same logic, you can get the document.body.innerHTML back:

source = driver.execute_script("return document.body.innerHTML;")
print(source)


来源:https://stackoverflow.com/questions/32981567/is-it-possible-to-get-contents-of-iframe-in-selenium-webdriver-python

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