user2379867
user2379867

Reputation:

How to print the webelement in protractor?

I want to print the element as part of a message when protractor times out waiting for the element.

waitForElementDisplayed(webDriverEl, time = timeOut) {
  let EC = protractor.ExpectedConditions;
  let isVisible = EC.visibilityOf(webDriverEl);
  browser.wait(isVisible, time, `Timed out waiting for element ${webDriverEl} to be visible`);
}

Have not had any luck trying to get the element to print correctly. Any help is appreciated.

Upvotes: 2

Views: 998

Answers (2)

Jothi Vignesh
Jothi Vignesh

Reputation: 45

I am getting "Failed: webElement.locator is not a function"

My code sample:

var clickOn = function(webElement){
    return webElement.click().then(()=> {
        console.log("Successfully clicked on the " + webElement.locator().toString());
    });

Upvotes: 0

Sudharsan Selvaraj
Sudharsan Selvaraj

Reputation: 4832

You can use element.locator().toString() to get the locator of a webelement.

browser.wait(isVisible, time, "Timed out waiting for element "+element.locator().toString() +" to be visible"); 

Upvotes: 1

Related Questions