Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protractor find an element by tag inside a div

I've got a div in an HTML Page of which the name is always known and inside this div there is an href, the details of which are not known. It could be the direct child of the parent or it could be a further grandchild. Looks something like this:

<div class="divName">
    ...
        <a href="some url">some text</a>
    ...
</div>

I know that there will only be one link within this div, so I want to find the one link and click it.

I've tried the following but it doesn't seem to be working:

    element(by.classname('divName')).find('a').click();

Any ideas?

like image 865
Robert McCraw Avatar asked Feb 03 '14 19:02

Robert McCraw


2 Answers

element(by.css('.divName a')).click();

Or the shorter notation:

$('.divName a').click();
like image 171
Andres D Avatar answered Sep 21 '22 15:09

Andres D


figured out a solution:

ptor.findElement(protractor.By.className('clsName'))
    .findElements(protractor.By.tagName('a'))
    .then(function(links){
        links[0].click();
        //place expects here, otherwise it will run async and your expects will be hit 
        //before the lookup
});

This seems to work pretty well for my purposes

like image 42
Robert McCraw Avatar answered Sep 21 '22 15:09

Robert McCraw