I need to locate a link on the page and copy it or store it as a string without clicking it in a protractor test. I can locate the element but am not sure how to store it as a string. Suggestions?

1 Answer 1


The problem is that all the selenium-specific Protractor methods return promises.

You will have to store the link as a "promise" and resolve once the value is needed:

var link = $("#mylink_id").getAttribute("href");

link.then(function (actualLinkAsString) {
    // do something with actualLinkAsString  
  • I'm having issues with this again. In my page object file, the link is located by css. What I need to do is click this link, and then store the url so that I can access it again later. Any recommendations on how to do sp?
    – kylokyler
    Sep 21, 2017 at 16:00
  • @Kelsey I think you can resolve the browser.getCurrentUrl() promise once you click the link. But, please do ask a separate question if you need further help. This way we are not going to pollute comments here and more people may potentially help you if it's a separate topic. Thanks for understanding.
    – alecxe
    Sep 21, 2017 at 16:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.