我正在尝试在nodejs中使用硒来自动化我的工作流程。当访问Sellercentral.amazon.com时,它将向我的手机发送一个OTP代码。如何在nodejs上要求提示,以便我输入代码?
我已经尝试过使用readline-sync,但是即使在硒开始之前也总是显示提示。
const webdriver = require('selenium-webdriver'),
By = webdriver.By,
until = webdriver.until;
const driver = new webdriver.Builder()
.forBrowser('firefox')
// .setFirefoxOptions(options)
.build();
//Main body
driver.get('https://sellercentral.amazon.com');
driver.wait(until.elementLocated(By.id('sign-in-button')));
driver.findElement(By.id('sign-in-button')).click();
const fillForm = (idToLook, keys) => {
this.idToLook = idToLook;
if (keys) {
driver.wait(until.elementLocated(By.id(idToLook)));
driver.findElement(By.id(idToLook)).sendKeys(keys);
}
else {
keys = readline.question(`what are the keys for ${this.idToLook}: `);
driver.findElement(By.id(idToLook)).sendKeys(keys);
}
}
fillForm('ap_email', amazon.id);
fillForm('ap_password', amazon.password);
driver.findElement(By.name('rememberMe')).click();
driver.findElement(By.id('a-autoid-0')).click();
driver.wait(until.elementIsNotVisible(By.id('auth-mfa-optcode')));
// fillForm('auth-mfa-otpcode');
driver.findElement(By.id('auth-mfa-remember-device')).click();
driver.quit();
答案 0 :(得分:0)
您可以尝试类似的方式。包装initializeSite以启动Promise网站。
基本脚本如下:
function main() {
var initializeSite = initialize();
initializeSite.then(function(result) {
// Do your different actions to bring up the form that need OTP
readline.question (“Add OTP”, (otp) =>{
// Add rest of your codes here
}
console.log(“success”)
}, function(err) {
console.log(err);
})
}