问题
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