【发布时间】:2015-05-03 02:34:39
【问题描述】:
我想创建一个 Selenium 测试来使用 AOL 邮件测试我们的扩展。我设法登录到 AOL 并撰写了一封电子邮件,但我还需要在 iframe 内的编辑器中选择元素。我检查过,即使打开编辑器,以下测试也失败了:
self.assertEqual(first=1, second=len(self.driver.find_elements_by_xpath(xpath="//iframe[@name='editor_body']//body[@contenteditable='true']")))
我收到错误 AssertionError: 1 != 0。如何通过 Xpath(或以任何其他方式使用 Selenium)选择 iframe 的主体和其他元素?
【问题讨论】:
-
您是否尝试过使用
.switch_to().frame(element)? -
@MarkRowlands 谢谢,它有效!但是
self.driver.switch_to.frame(frame_reference=self.driver.find_element_by_xpath(xpath="//iframe[@name='editor_body']"))
标签: python selenium iframe xpath