Reputation: 383
I have this HTML and try to parse Barcode
</div>
<div class="bc">
<div class="pititle">
<h2 itemprop="name">Bath Shelf - 5 Pack</h2>
</div>
<div class="brandmanu model">
<h5>Product code</h5>
<h6>BA0576</h6>
</div>
<div class="brandmanu gtin">
<h5>Barcode</h5>
<h6>5056170307192</h6>
</div>
<div class="brandmanu inner">
<h5>Inner Barcode</h5>
<h6>NO INNER</h6>
</div>
<div class="brandmanu outer">
<h5>Outer barcode</h5>
<h6>25056170307196</h6>
</div>
<div class="brandmanu brand" itemprop="brand" itemscope="" itemtype="http://schema.org/Brand">
I try to write this code, but don't get the result:
element = driver.find_element_by_class_name("brandmanu gtin")
tag_list = driver.find_elements_by_xpath("//div[@class='brandmanu gtin']")
print(element)
print(tag_list)
For find_element_by_class_name
I get the error:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".brandmanu gtin"}
(Session info: chrome=89.0.4389.90)
Please, advise, how to fix code.
Upvotes: 1
Views: 151
Reputation: 4212
Get it by css
selector:
element = driver.find_element_by_css_selector(".brandmanu.gtin>h5").text
To get the value use:
element = driver.find_element_by_css_selector(".brandmanu.gtin>h6").text
Dot is used for classes.
If you prefer xpath
:
element = driver.find_element_by_xpath('//div[@class="brandmanu gtin"]/h5').text
Upvotes: 1