Manta
Manta

Reputation: 51

Best way to locate link with protractor

<a href="someCoolLinkText.com">
    <h3 class="main-header"> 
        COOL LINK 
    </h3>
 </a>

What is best way to find and click on this link?

Upvotes: 0

Views: 435

Answers (3)

Andersson
Andersson

Reputation: 52665

Try to locate required node by its link text:

element(by.linkText('COOL LINK')).click()

Note that you should use text exactly as it appears on page, but not as it appears in HTML source code

Update

You can try to use ExpectedCondition to wait for link appearance in DOM:

var EC = protractor.ExpectedConditions;
browser.wait(EC.elementToBeClickable(element(by.linkText('COOL LINK'))), 5000).click();

Upvotes: 2

undetected Selenium
undetected Selenium

Reputation: 193108

The text COOL LINK is within <h3> tag so you can use xpath as :

//a[@href='someCoolLinkText.com']/h3[@class='main-header' and contains(.,'COOL LINK')]

Upvotes: 0

Ankur Singh
Ankur Singh

Reputation: 1289

You can use this xpath :- //h3[text()='COOL LINK']

Upvotes: 0

Related Questions