title: How to locate the value inside a div using Selenium and Python
body: <p>How to locate value inside a div using xpath \ css_selector</p>
  <p>I have this html:</p>
  <pre><code>&lt;div class=&quot;catalog-products view-tile&quot; data-catalog-products=&quot;&quot; data-slider-available=&quot;&quot; data-primary-as-icon=&quot;&quot;&gt;&lt;div data-id=&quot;product&quot; class=&quot;catalog-product ui-button-widget&quot; data-product=&quot;5a7b4c6d-0bc3-11ec-a2b0-00155dfc8232&quot; data-code=&quot;4862447&quot; data-preview-slider-inited=&quot;1&quot;&gt;&lt;div class=&quot;catalog-product__image&quot;&gt;&lt;a class=&quot;catalog-product__image-link&quot; href=&quot;/product/5a7b4c6d0bc3c823/videokarta-msi-geforce-210-n210-1gd3lp/&quot; data-toggle-slider=&quot;&quot;&gt;&lt;picture&gt;&lt;source type=&quot;image/webp&quot; media=&quot;(min-width: 768px)&quot; etc
  </code></pre>
  <p>So I need to get data-code value <strong>4862447</strong></p>
  <ol>
  <li><p>Tried to access via xpath:</p>
  <pre><code>/html/body/div[1]/div/div[2]/div[2]/div[3]/div/div[1]/div[1]
  </code></pre>
  <p>Got highlighted in Chrome console that part:</p>
  <pre><code>&lt;div data-id=&quot;product&quot; class=&quot;catalog-product ui-button-widget&quot; data-product=&quot;5a7b4c6d-0bc3-11ec-a2b0-00155dfc8232&quot; data-code=&quot;4862447&quot; data-preview-slider-inited=&quot;1&quot;&gt;
  </code></pre>
  <p>Don't know how to get data-code value.</p>
  </li>
  <li><p>Tried css_selector:</p>
  <pre><code>div[data-id='product']
  </code></pre>
  <p>Got same line:</p>
  <pre><code>&lt;div data-id=&quot;product&quot; class=&quot;catalog-product ui-button-widget&quot; data-product=&quot;5a7b4c6d-0bc3-11ec-a2b0-00155dfc8232&quot; data-code=&quot;4862447&quot; data-preview-slider-inited=&quot;1&quot;&gt;
  </code></pre>
  <p>And no idea again.</p>
  </li>
  </ol>