카테고리 없음

Selenium으로 DOM요소 선택하는 방법

funfunweb 2024. 6. 13. 13:47

DOM 내부에 있는 여러 개의 요소 중 처음 찾아지는 요소를 추출

메서드 이름 설명
find_element_by_id(id) id속성으로 요소를 하나 추출
find_element_by_name(name) name속성으로 요소를 하나 추출
find_element_by_css_selector(query) css선택자로 요소를 하나 추출
find_element_by_xpath(query) XPath를 지정해 요소를 하나 추출
find_element_by_tag_name(name) 태그 이름이 name에 해당하는 요소를 하나 추출
find_element_by_link_text(text) 링크 텍스트로 요소를 추출
find_element_by_partial_link_txt(text) 링크의 자식 요소에 포함돼 있는 텍스트로 요소를 하나 추출
find_element_by_class_name(name) 클래스 이름이 name에 해당하는 요소를 하나 추출

 

DOM 내부에 있는 모은 요소 추출

메서드 이름 설명
find_elements_by_css_selector(query) css 선택자로 요소를 여러 개 추출
find_elements_by_xpath(query) XPath를 지정해 요소를 여러 개 추출
find_elements_by_tag_name(name) 태그 이름이 name에 해당하는 요소를 여러 개 추출
find_elements_by_class_name(name) 클래스 이름이 name에 해당하는 요소를 여러 개 추출
find_elements_by_partial_link_text(text) 링크의 자식 요소에 포함돼 있는 텍스트로 요소를 여러 개 추출