簡體   English   中英

如何使用Selenium Webdriverjs在承諾鏈中使用sendkeys函數?

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

這是代碼:

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

錯誤:

TypeError:txtFnn.sendkeys不是函數

我假設很多是因為您沒有提供很多信息,但是從代碼中,我假設driver.findElement返回了Promise ...

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

那樣有用嗎? 如果是這樣,我將首先說明您出了問題的地方,但如果沒有,那么就沒有時間浪費時間解釋我的假設了

您的代碼可以簡化為:

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

您可以嘗試一下並告訴我是否仍然出現錯誤嗎? 您確定xpath正確嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM