2017-10-30 2 views
-1

클래스의 ID 값을 가져 오려고합니다. 예 :Selenium을 사용하여 ID를 얻는 방법

<div class="a_class_name_a" an_identifier="1" id="the_requered_id_like_54656"></div> 
<div class="a_class_name_a" an_identifier="2" id="the_requered_id_like_4565"></div> 
<div class="a_class_name_a" an_identifier="3" id="the_requered_id_like_12"></div> 
<div class="a_class_name_b" an_identifier="4" id="the_requered_id_like_786"></div> 
<div class="a_class_name_c" an_identifier="5" id="the_requered_id_like_566"></div> 

가 어떻게 셀레늄 Webdriver 파이썬을 사용하여 내 선택 기준으로 = "4"an_identifier와 ID 값 "the_requered_id_like_786"을받을 수 있습니까?

+0

당신은 DIV 요소를 통해 반복하고 확인할 수 있습니다 경우 elem.get_attribute ("an_identifier") == "4"다음 elem.get_attribute는 ("ID")는 것입니다 "the_requered_id_like_786"이 (가) –

+0

Thx입니다. 나는 너의 대답을 시도 할 것이다. – Luc

+1

[Selenium에서 요소의 속성을 얻는 방법?] (https://stackoverflow.com/questions/30324760/how-to-get-attribute-of-element-from-selenium) – Andersson

답변

0
당신은 이런 식으로 할 수

:

id= driver.find_element_by_xpath("//div[@class='a_class_name_b' and @an_identifier='4']").get_attribute("id") 
print(id) 
+0

감사합니다. 저는 파이썬에 관한 초심자이지만 여전히 문제가 있었지만 솔루션이 마침내 성공했습니다. – Luc

+0

@Luc 기꺼이 도와 드리겠습니다. –

관련 문제