Angular + Selenium: cannot get value from input field

I wrote my tests in Protractor and I used the expect statement:

loginPage.email.sendKeys( params.login.email );
expect(loginPage.email.getText()).toEqual( params.login.email );

However, my test fails because signUpPage.email.getText () returns an empty string. I could not find which function to call in the Selenium documentation for the input field to return the correct value?

In my Protractor.conf file:

 params: {
      login: {
        email: 'user@email.com',
        password: 'blahblah123'
      }

Error in terminal:

Expected to be 'equal to' user@email.com '.

So, I'm trying to match that the input of the email field is the same as the email address I sent. Any suggestions on how to do this in Selenium?

+4
source share
3 answers

input, value:

expect(loginPage.email.getAttribute("value")).toEqual(params.login.email);

, Saifur , , , textToBePresentInElementValue

var EC = protractor.ExpectedConditions;
browser.wait(EC.textToBePresentInElementValue(loginPage.email, params.login.email), 5000);

, - ( ) .

+3

, - . ExpectedCondition , .

var EC = protractor.ExpectedConditions;
browser.wait(EC.textToBePresentInElement(loginPage.email ,params.login.email));

. @alecxe

browser.wait(EC.textToBePresentInElementValue(loginPage.email, params.login.email), 5000);
+1

, AngularJS, WebDriver, .

FirefoxWebDriver, .

JavascriptExecutor JavaScript .

If your web project has a jQuery plugin, you can use the following method:

WebDriver driver = DriverFactory.getDriver();

public String getTextAt(String cssId) {
    if (driver instanceof JavascriptExecutor) {
        JavascriptExecutor javascriptExecutor = (JavascriptExecutor) driver;
        return (String) javascriptExecutor.executeScript("return $('" + cssId + "').val();");
    }
    return null;
}

If you want to use raw javascript, you can do it like this:

WebDriver driver = DriverFactory.getDriver();

public String getTextAt(String cssId) {
    if (driver instanceof JavascriptExecutor) {
        JavascriptExecutor javascriptExecutor = (JavascriptExecutor) driver;
        return (String) javascriptExecutor.executeScript("return documenet.getElementById('" + cssId + "').value;");
    }
    return null;
}

Note that in this case cssId must be an id attribute.

+1
source

All Articles