我想创建一个 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)?
推荐答案在切换到
You cannot traverse through <iframe>'s until switching to them. Your xPath,
//iframe[@name='editor_body']//body[@contenteditable='true']将不起作用,因为 标记位于 iFrame 内,而该 iFrame 不在当前上下文中.你需要先切换到它:
will not work because the <body> tag is within an iFrame, which is not in the current context. you need to switch to it first:
driver.switch_to.frame('editor_body')...更多推荐
如何使用 Xpath 在 iframe 中选择元素?
发布评论