• Slider Banner

    Prepare for

    Technical Interview

    Over .1 Million+ Interview Questions for different profiles

    Read More
  • Slider Banner

    Join the

    Programming World

    Learn about top programming languages, tools and frameworks.

    Read More
  • Slider Banner

    Prepare with

    Certification MCQ

    Practice for certification from 1000+ multiple choice questions.

    Read More

How to accept Alert in Protractor?

By using accept() method of Alerts class, we accept Alerts in Protractor.

Note: We have to switch the control to the alert using switchTo().alert() before accepting the alert.

browser.switchTo().alert().accept()

How to get text from a textbox in Protractor?

By using getAttribute method by passing argument as value. getAttribute() method returns a promise which contains String:

Example

element(by.xpath("text box xpath").getAttribute("value")).then(function(textValue)
{
    console.log(textValue)
});

Why getText() method returns Object instead of String in Protractor?

When using Java, getText() method returns the corresponding text from the element. However in Protractor, getText() method returns Object something like [objectObject].

In Protractor, the getText() method returns a Promise. We need to resolve this in order to get the text.

Syntax:

element.getText().then(function (text)
{ 
    console.log(text); 
});

How do you verify tooltip text using Protractor?

We can verify tooltip text using protractor by fetching the value of ‘title’ attribute.

element(by.id("some")).getAttribute("title").then(function(tooltip)
{
    console.log(tooltip);
}
Subscribe to