我想創建一個Selenium測試,用AOL郵件測試我們的擴展。我設法登錄到AOL並撰寫電子郵件,但我還需要選擇編輯器內部的元素,它位於iframe中。我檢查,甚至當編輯器打開下面的測試失敗:如何使用Xpath選擇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)'? – 2015-03-02 17:16:41
@MarkRowlands謝謝,它的工作原理!但是用'self.driver.switch_to.frame(frame_reference = self.driver.find_element_by_xpath(xpath =「// iframe [@ name ='editor_body']」))' – Uri 2015-03-03 15:32:27