当前位置: 动力学知识库 > 问答 > 编程问答 >

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

问题描述:

In web testing, I plan to get contents of iframe(/htme/body/p), is is 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()

网友答案:

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

source = driver.execute_script("return document.body.innerHTML;")
print(source)
分享给朋友:
您可能感兴趣的文章:
随机阅读: