Dmytro
Dmytro

Reputation: 65

Ruby/Selenium can't receive text

I'm using the "firepath" Firefox extension to test my xpaths.

Running this xpath:

driver.find_elements(:xpath, "//path/a[@class='anytext']").map{|el| el.text}

against this anchor:

<a class="anytext" href="/any/path/" title="Search for skill">text</a>

I received all elements on page as [string1, string2....]

With this xpath:

driver.find_elements(:xpath, "//path/a[@class='anytext and']").map{|el| el.text}

and this anchor:

<a class="anytext andmore" href="/any/path/" title="Search for skill" aria-describedby="tooltip">text</a>

I received array [" ", " ", ....] without text.

I understand that the problem is to do with "aria-describedby" but I dont know what to try next? I tried using different methods but not getting what I need.

Upvotes: 0

Views: 44

Answers (2)

Dmytro
Dmytro

Reputation: 65

I solved the problem with firebug This is hidden elements with attribute: 'innerHTML' or 'textContent'

i.e.:

driver.find_elements(:css, "path to elements").map{|el| el.attribute('textContent')}

Upvotes: 0

Amey
Amey

Reputation: 8548

There are multiple classes so try contains and and in your xpath instead:

driver.find_elements(:xpath, "//path/a[contains(@class, 'anytext') and contains(@class, 'and')]").map{|el| el.text}

Conversely you could search by css selectors:

driver.find_elements(:css, "path a.anytext.and").map{|el| el.text}

Upvotes: 1

Related Questions