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']")))
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,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: