Majid
Majid

Reputation: 95

Selenium, get the href if this link in Ruby

I am new to testing and Selenium,

I am trying to assert two texts, I have already got the first one by:

driver.current_url

but I stuck to get the text of this href as the second text:

HTML code:

<div class="back">
  <a href="/applicant_submissions">
    <i class="glyphicon glyphicon-chevron-left"></i>
    BACK
  </a>    
</div>

Ruby code:

element = driver.find_elements(:class,'view-link')[0].click
puts element
puts driver.current_url

div = driver.find_element(:class,'back')   
url = driver.findElement(By.linkText("BACK"))
puts url.href

At the end, I want to compare driver.current_url with url.href, but I could not get the href of this back button link.

Thanks.

Upvotes: 4

Views: 2444

Answers (1)

Ratmir Asanov
Ratmir Asanov

Reputation: 6459

Try to use CSS selector for finding "BACK" link: .back>a.

Code: url = driver.find_element(:css, ".back>a").attribute("href").

Upvotes: 3

Related Questions