iframe이 : 다른 프레임 / 페이지 내에 중첩 페이지, 또한 HTML 페이지에 포함 된 다른 즉, HTML 페이지, 그러나 이것은 HTML </ 프레임> </ iframe> 해당 태그 쌍에 포함 .
python3.8 해당 셀레늄 그것은 iframe이의 콘텐츠를 두 가지 방법을 제공합니다 :
方式 一 : driver.switvh_to.frame (frame_reference)
구문 :
driver.switch_to.frame (iframe 대응의 이름 또는 객체 속성 또는 webelement 첨자)
예 :
driver.switch_to.frame ( "login_frame_qq") # login_frame_qq의 이름이 Iframe으로 전환
driver.switvh_to.frame (0)는 제 #에서 Iframe으로 전환
// DIV ((By.xpath "driver.switch_to.frame [클래스 @ = "ptlogin_wrap"] ))
方式 二 : frame_to_be_available_and_switch_to_it (frame_reference)
앞에서의 일반적인 작업 셀레늄 대기 동작 , 우리는, 도입 방법 expected_conditons 모듈을 제공했다.
이 방법은 iframe 사용할 판단하고, 자동적으로는 Iframe으로 전환한다.
일관된 방식으로 frame_reference 값.
예 :
셀레늄 수입 webdriver에서
selenium.webdriver.support.wait 수입 WebDriverWait에서
EC 등 selenium.webdriver.support 수입 expected_conditions에서
selenium.webdriver.common.by 수입에서 저자
WebDriverWait .until (드라이버, 20) (EC.frame_to_be_available_and_switch_to_it (iframe_name))
페이지는 iframe이 iframe에있을 때이 시점에서 우리가 보조은 iframe을 입력하려는 경우 때, 당신은 iframe이를 입력해야하고 보조은 iframe을 입력 할 수 있습니다.
#iframeId가 iframe을 아이디 중 하나입니다 driver.switch_to_frame ( "iframeId") , 우리는 TAG_NAME를 통해 #iframeId은 iframe에서 두 개의 평행을 가지고 있지만 그들은 ID와 이름이없는 얻을 수 있습니다 (driver.find_elements_by_tag_name (driver.switch_to.frame "은 iframe ') [1])
우리가 입력 그래서 다음 단계는 iframe이를 iframeId!
iframe을 밖으로 셀레늄
두에 Iframe은 iframe, 즉 스킵 부모 점프 ① :
. driver.switchTo () parentFrame (),
# 또는
driver.switch_to.parent_frame ()
은 iframe에서 메인 창으로 건너 뛰기 ②
driver.switch_to_default_content ()
#或者
driver.switch_to.default_content ()