Home > Blockchain >  How to get value of nested class with Selenium Python
How to get value of nested class with Selenium Python

Time:02-03

Hello i have problem i don't know how to get value of offer__name and offer_price.

<div >
  <div >
      <em> item1 </em>
      <em> description of item1 </em>
  </div>
  <div >500</div>
</div>

<div >
  <div >
      <em> item2 </em>
      <em> description of item2 </em>
  </div>
  <div >200</div>
</div>

<div >
  <div >
      <em> item3 </em>
      <em> description of item3 </em>
  </div>
  <div >100</div>
</div>

i try with

objects = driver.findElement(By.xpath("//*[@class='offer']")));
for offer in objects:
    ...

but for-loop get me notice that object can't be iterated, can you help me?

I just want value like: item1 description of item1 500, item2 description of item2 200, item3 description of item3 100,

CodePudding user response:

It is simple just grab the elements in list. You need find_elements_*() method to get list of elements where as you are using - find_element_*()
code for your reference -

lst_ele = driver.find_elements_by_xpath(".//div[@class='offer']")
    for i in lst_ele:
        print(i.text)

Output -

enter image description here

  •  Tags:  
  • Related