Yiren Lu
Yiren Lu

Reputation: 153

Accessing inner text of a div returning empty string

I'm trying to extract the answer text on the following webpage. I opened up the DOM inspector and got the class of the text as "answer_content". I've defined a method that looks like:

def get_answer()
  @browser.div(:class, "answer_content")
end 

puts page.get_answer.text

However, this prints an empty spring. Did I identify the wrong element? When I look at it in the DOM inspector, there does seem to be nothing in between the divs.

Upvotes: 1

Views: 1024

Answers (1)

Željko Filipin
Željko Filipin

Reputation: 57312

Looks to me that there are more than one div elements with that class. This will tell you if my guess was correct:

@browser.divs(:class, "answer_content").size

Upvotes: 1

Related Questions