Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 338
Majid Avatar asked Sep 18 '25 22:09

Majid


1 Answers

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

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

like image 193
Ratmir Asanov Avatar answered Sep 23 '25 11:09

Ratmir Asanov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!