在web测试中,我打算获取iframe(/html/body/p)的内容,可以吗?
我使用此方法设置 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()
请您参考如下方法:
为了遵循相同的逻辑,您可以获得 document.body.innerHTML 返回:
source = driver.execute_script("return document.body.innerHTML;")
print(source)
