user1875703
user1875703

Reputation: 169

Selenium WebDriver ruby accessing span value

What is the best way to to select this element using Selenium WebDriver?

I am trying to access the <span> element through the class mapResultNumber. This is the actual HTML:

<div class="mapResultInner">
<div class="mapResultNumber">
<span>4</span>
</div>

Upvotes: 0

Views: 2056

Answers (2)

bbbco
bbbco

Reputation: 1540

Using a css selector is a more readable way:

element = @driver.find_element(:css => "div.mapResultNumber span")
  • A dot (period) after a tag indicates the class to select.
  • A single space after the first selector (i.e. "div.mapResultNumber") indicates the next tag will be found inside the previous
  • You could also use div.mapResultNumber > span to indicate that the span tag is found directly beneath the div

Upvotes: 0

Amey
Amey

Reputation: 8548

You could use xpath = //div[@class='mapResultNumber']/span

Upvotes: 1

Related Questions