在自動化測試中涉及到frame跳轉時,總會出現元素定位不到的問題,
假如我們已經定位到name='Top'中,現在我們要去定位name='Menu',有三種解決方案:
1.使用switch_to.parent_frame(),相當于跳轉到上一級frameset
self.driver.switch_to.parent_frame()
driver.switch_to_frame("Menu")
2.使用swtich_to_default_content(),相當于跳轉到最外層頁面
driver.switch_to_default_content()
#driver.switch_to.default_content()
driver.switch_to_frame("Menu")
3.先定位到同一級的frameset中,再定位frame(注:該頁面無法操作)
因為本頁面frameset沒有id或name,如果有id或name為content,可采用下述方法。
frameset=driver.find_element_by_id("content")
frame=frameset.find_element_by_name("Menu")
driver.switch_to_frame(frame)