Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

I want to create a Selenium test to test our extensions with AOL mail. I managed to log in 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 frame and other elements by Xpath (or in any other way with Selenium)?

1 Answer

0 votes
by (62.9k points)

You cannot traverse through <iframe>'s until switching to them. Your XPath,

iframe[@name='editor_body']//body[@contenteditable='true']

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')

Browse Categories

...