본문 바로가기
Programming/Errors

[Python, Selenium] find_element를 통해 요소가 찾아지지 않는다면?

by Brian Go 2022. 6. 18.

웹 크롤링 중 find_element 메서드를 이용해서 값이 찾아지지 않는다면, 아마 iframe이라는 태그가 존재해서일 것이다. 

iframe은 하나의 프레임을 만드는 태그인데, 쉽게 말하면 html 안에 따로 html을 담는 프레임이다. 

따라서 프레임을 한 번 바꿔준 후에 find_element를 해줘야 한다.

 

driver.find_element_by_id("searchIframe") #iframe 태그 엘리먼트 찾기
driver.switch_to.frame(element) #프레임 이동
driver.find_element(By.XPATH, '//*[@id="_pcmap_list_scroll_container"]/ul')

 

댓글