0

I am trying to get the text in the elements with li class ="tooltip icon-bed" from the below html and I expect to get value "2" in this example but I always get an empty value instead.

<div class="listing-info-mobile">
     <p class="icon-location">
                Residencial            </p>
     <div class="details">
         <p class="price">
                   1,654,080                </p>
         <ul class="features">
                 <li original-title="Recámaras" class="tooltip icon-bed">2</li>
                 <li original-title="Baños" class="tooltip icon-bath">1</li>
                 <li original-title="Superficie (m²)" class="tooltip icon-building-area">69</li>
         </ul>
      </div>
 </div>

Here is the part of my code that is trying to get the text:

extract=driver.find_elements_by_xpath("//ul[@class='features']")
for item in extract:
            print item.find_element_by_class(".//li[@class='tooltip icon-bed']").text

It seems to find the elements but text is always empty. Any idea?

3
  • Is this text visible on the page?? Commented Nov 24, 2016 at 14:57
  • Because the text needs to be directly in that element, features does not contains any text, contains other elements and those elements contain text. Commented Nov 24, 2016 at 14:59
  • Try once in one line as driver.find_element_by_css_selector("ul.features > li.icon-bed").get_attribute("textContent") and let me know Commented Nov 24, 2016 at 15:00

2 Answers 2

4

driver.find_element_by_css_selector("ul.features > li.tooltip.icon-bed").get_attribute("innerHTML") This should do the trick :)

Sign up to request clarification or add additional context in comments.

Comments

1

get_attribute("innerHTML") worked for me. Apparently, when you are using Django/Python, .text is not working. It always comes as blank. However, innerHTML is coming as expected and hence assertion works.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.