Home > Net >  how to get div properties text in python selenium webdriver
how to get div properties text in python selenium webdriver

Time:07-08

Hope all are doing well. I want to get "data-id" property text. Please anyone help me here to get that. Thanks in advance.

<div >
  <div >
    <div data-id="MOBG6WQWRGRRDBH6" style="width: 100%;">
      <div  data-tkid="82daf062-714d-464f-b670-ce7681250431.MOBG6WQWRGRRDBH6.SEARCH">
      </div>
    </div>
  </div>
</div>

CodePudding user response:

Use CSS selector to find div element with data-id attribute

driver.find_element('css selector', 'div[data-id]').getAttribute('data-id')

Note: since your HTML sample is small this code would work. On a bigger sample, narrow down to the parent of your target div element, or use find_elements instead and filter for the element you want.

Reference reading: All CSS Attribute Selectors

CodePudding user response:

String dataId = driver.FindElement(By.xpath("//div[@class='_2kHMtA']/..")).getAtribute("data-id");
  • Related