0

Enabling certain options on a page will generate a link that I need to store. The link is located in the page object file by element(by.css('a[href*="link"]')); I need to figure out how to store either the link located on the page or the link after it is clicked (the same URL).

Suggestions?

1
  • what is the level of your JavaScript skills? What prevents you to store the reference of the located webelement? Where and why you want to store it? How you will use it after subsequent retrieval? I am asking all these question to make sure I am not missing something trivial Sep 21 '17 at 16:31
1

To get to the actual link href value, you need to use .getAttribute() method:

element(by.css('a[href*="link"]')).getAttribute("href").then(function (href) {
    console.log(href);
});

This approach would work if you have this element available on the page and you need to use the href value in the same test afterwards:

it("should test something", function () {
    // do something

    yourPageObject.yourLinkElement.getAttribute("href").then(function (href) {
        // do something with the link
    });
});

But, if you need this link in other tests later in this test file, you may take advantage of the it blocks to be executed sequentially by jasmine/protractor:

var hrefValue;
it("should test something", function () {
    // do something

    yourPageObject.yourLinkElement.getAttribute("href").then(function (href) {
        hrefValue = href;
    });
});

it("should test something else", function () { 
    console.log(hrefValue);
});

I don't though particularly like the idea of coupling the tests - making one tests depend on the other to be executed before it. Generally, it is not a good idea.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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