简体   繁体   English

如何使用Selenium Webdriverjs在承诺链中使用sendkeys函数?

[英]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 TypeError:txtFnn.sendkeys不是函数

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.findElement返回了Promise ...

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? 您确定xpath正确吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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