-1

I want to obtain a value of an ID in a class. Example:

<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>

How do I obtain the value "the_requered_id_like_786" of id with an_identifier="4" as my selection criteria using Selenium Webdriver and Python?

Luc
  • 223
  • 2
  • 13
  • You could iterate through the div elements and check if elem.get_attribute("an_identifier") == "4" then elem.get_attribute("id") will be "the_requered_id_like_786" – Abdul Niyas P M Oct 30 '17 at 16:52
  • Thx. I will try your answer. – Luc Oct 30 '17 at 16:56
  • 1
    Possible duplicate of [How to get attribute of element from Selenium?](https://stackoverflow.com/questions/30324760/how-to-get-attribute-of-element-from-selenium) – Andersson Oct 30 '17 at 17:53

1 Answers1

0

You could do in this way:

id= driver.find_element_by_xpath("//div[@class='a_class_name_b' and @an_identifier='4']").get_attribute("id")
print(id)
Davide Patti
  • 3,391
  • 2
  • 18
  • 20