Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to log an element using protractor?

Tags:

protractor

I'm trying to locate an element using protractor but I can't find it. To debug, I'd like to look at the element I did find and see which one it is. I have some code like this:

      myElement.all(by.cssContainingText('.name', 'value')).then(function (elems) {
    console.log(elems.length); <--- this line logs "2"
    console.log(elems[1]); <--- this line logs "{ ptor_: ...."
    elems[1].getInnerHtml().then(function(html){
        console.log(html); <--- never gets here
    }); });

How can I see what elements the all() method found?

like image 948
bea Avatar asked Jul 06 '26 13:07

bea


1 Answers

Not sure if it's the best/most concise way, but you should be able to use map to loop over the elements, and use getOuterHtml() on each to access the HTML

myElement.all(by.cssContainingText('.name', 'value')).map(function(el) {
  return el.getOuterHtml();
}).then(function(html) {
  console.log(html);
});
like image 141
Michal Charemza Avatar answered Jul 09 '26 09:07

Michal Charemza



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!