Use sendKeys and store value in variable

1k Views Asked by At

Currently I'm using WebdriverJS and trying fill a form. My test is open form > fill the field with sendKeys and store this value for the variable. Follow my code:

driver.findElement(By.xpath("//a[contains(text(),'Añadir Propuesta   Test')]")).click();
driver.wait(function () {
    return driver.isElementPresent(By.css(".form-control.col-md-8")); 
}, 15000);
var propuesta = driver.findElement(By.name('rut'));
propuesta.sendKeys('1111122222');
propuesta.getText().then(function(text){
        console.log(text);
    });

My actual result is returning empty value

enter image description here

How can I use sendKeys and store the same value sent?

1

There are 1 best solutions below

5
Florent B. On BEST ANSWER

The text you typed is stored in the value attribute:

propuesta.getAttribute('value').then(function(text){
    console.log(text);
});