我的硒有问题。我已经输出了从提交的请求中弹出的字符串的模态。我正在寻找使用findElement使用xpath捕获该数据,并将字符串返回到控制台。看来诺言没有解决,我不确定如何将其包装在诺言中,以便得到诺言的结果。
在ws://127.0.0.1:60822 / devtools / browser / a2114051-85ec-47d7-9d62-9f9809ef732c上监听的DevTools
测试通过
表格
承诺{<等待中}
var webdriver = require('selenium-webdriver'),
By = webdriver.By,
until = webdriver.until;
USERNAME = 'XXXXXX';
PASSWORD = 'XXXXXXXX';
WEBSITE = 'https://XXXXXXXXXXXXXX/';
var driver = new webdriver.Builder()
.forBrowser('chrome')
.build();
//tag[text()=’text value‘]
driver.get(WEBSITE);
driver.sleep(4000).then(function() {
driver.findElement(By.id('username')).sendKeys(USERNAME);
driver.findElement(By.id('password')).sendKeys(PASSWORD);
driver.findElement(By.id('submit1')).click();
});
driver.sleep(26000).then(function() {
driver.getTitle().then(function(title) {
if (title === 'Forms') {
console.log('Test passed');
console.log(title);
driver.findElement(By.xpath("//*[text() = 'Request']")).click();
//driver.findElement(By.id('market')).selectBuyValue('CI').click();
//*[@id="request"]/div[3]/div/input
driver.sleep(4000).then(function() {
driver.findElement(By.xpath("//*[@id='market']")).sendKeys("CI");
driver.findElement(By.xpath("//*[@id='request']/div[3]/div/input")).click();
});
driver.sleep(10000).then(function() {
console.log(driver.findElement(By.xpath("//*[@id='myModal']/div/div/div[1]/div")).getText());
//THIS WORKS driver.findElement(By.xpath("//*[@id='myModal']/div/div/div[2]/button")).click();
});
} else {
console.log(title);
console.log('took to long');
}
});
});
答案 0 :(得分:0)
driver.findElement()
和WebElement.getText()
方法都返回一个Promise,因此您将不得不在await
函数中async
进行调用-https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function-或增加通过像其他promise实例一样调用then()
方法来回调地狱。