-1

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?

Rafael C.
  • 2,245
  • 4
  • 29
  • 45

1 Answers1

2

The text you typed is stored in the value attribute:

propuesta.getAttribute('value').then(function(text){
    console.log(text);
});
Florent B.
  • 41,537
  • 7
  • 86
  • 101
  • Worked @Florent, thanks! Another question: What's the better way to fill all form (storing values in a variable) and check this value in another method? Actually this is not work for me: http://take.ms/bQNAm – Rafael C. Oct 11 '16 at 19:21
  • Your variable `rut` is declared in the function and is therefore disposed when the function returns. Either assign it to the context `this.my_field_text = text` or to a local variable declared in your module. – Florent B. Oct 11 '16 at 19:58
  • Give me an example, please? – Rafael C. Oct 11 '16 at 20:04
  • Assign `this.my_field_text = text` in the function `addPropuesta`. You should then be able to read the value in `checkPropuestaAdded` by getting `this.my_field_text`. – Florent B. Oct 11 '16 at 20:11
  • @Rafael if this answered your question, please make sure you accept it. If it (or any answer) is useful, please upvote it also. – JeffC Oct 12 '16 at 15:33