如何使用 Xpath 在 iframe 中选择元素? [英] How do I select elements inside an iframe with Xpath?

查看:23
本文介绍了如何使用 Xpath 在 iframe 中选择元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个 Selenium 测试来使用 AOL 邮件测试我们的扩展.我设法登录到 AOL 并撰写了一封电子邮件,但我还需要在 iframe 内的编辑器中选择元素.我检查过,即使打开编辑器,以下测试也失败了:

I want to create a Selenium test to test our extensions with AOL mail. I managed to login to AOL and compose an email, but I also need to select elements inside the editor, which is inside an iframe. I checked and even when the editor is open the following test fails:

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 和其他元素的主体?

I get the error AssertionError: 1 != 0. How do I select the body of the iframe and other elements by Xpath (or in any other way with Selenium)?

推荐答案

在切换到