简体   繁体   中英

How to use sendkeys function with promise chaining using selenium webdriverjs?

This is the code:

 driver.get(url).then(function(){
         txtFnn = driver.findElement(webdriver.By.xpath(xpath));
         return txtFnn;
    }).then(function(){
           txtFnn.sendkeys("12345678");
    })

Error:

TypeError: txtFnn.sendkeys is not a function

I'm assuming a lot because you don't supply much info, but from the code, I assume that driver.findElement returns a Promise ... so

driver.get(url).then(function(){
         return driver.findElement(webdriver.By.xpath(xpath));
    }).then(function(txtFnn){
           txtFnn.sendkeys("12345678");
    })

Does that work? If so, I'll explain where you went wrong in the first place, but if not, there's no point wasting time on explaining something comes from my assumptions

your code can be simplified as:

driver.get(url);
txtFnn = driver.findElement(webdriver.By.xpath(xpath));
txtFnn.sendkeys("12345678");

can you try this and tell me if you are still getting the error? are you sure that the xpath is correct?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM