問題:操作某元素時,總是定位不上,此時需要確認你在哪個iframe里。
如圖html代碼,有很多個iframe,代碼如下
定位問題的代碼:
獲取當前iframe的tag name,確定有幾個iframe,你所在的元素和獲取到頁面的iframe之間的關系,來進行iframe的切換。
for child_frame in driver.find_elements_by_tag_name("iframe"): child_frame_id = child_frame.get_attribute("src") print(child_frame_id)