Selenium Node.js将控制转移到其他选项卡

Selenium Node.js将控制转移到其他选项卡,node.js,selenium,testing,automation,qa,Node.js,Selenium,Testing,Automation,Qa,目前我正在使用Node.js进行Selenium自动化测试。我发现了一些使用Selenium无法实现的操作。详情如下 我目前的先决条件是在一些电子邮件网站上打开deeplink的新标签。点击deeplink后,“更改我的密码”将重定向到我的网站并继续更改密码过程。如何将控件转移到其他选项卡 //after click on deeplink, open new tab driver.getAllWindowHandles().then(function gotWindowHandles(all

目前我正在使用Node.js进行Selenium自动化测试。我发现了一些使用Selenium无法实现的操作。详情如下

我目前的先决条件是在一些电子邮件网站上打开deeplink的新标签。点击deeplink后,“更改我的密码”将重定向到我的网站并继续更改密码过程。如何将控件转移到其他选项卡

//after click on deeplink, open new tab

driver.getAllWindowHandles().then(function gotWindowHandles(allhandles) {
       return driver.switchTo().window(allhandles[allhandles.length - 1]);
 });

let newtab = driver.findElement(By.xpath('//*[@id="new_password"]'));

await driver.wait(until.elementLocated(newtab));
await driver.wait(until.elementIsVisible(driver.findElement(newtab))).sendKeys('Tester123!!');
//enter confirm password
await driver.findElement(By.xpath('//*[@id="confirmpass"]')).sendKeys('Tester123!!');
任何帮助都将不胜感激


提前谢谢你。

哎呀,我发现了我的错误。我应该使用By.xpath而不是driver.findElement来定位,这样会得到不同的结果

//after click on deeplink, open new tab

driver.getAllWindowHandles().then(function gotWindowHandles(allhandles) {
       return driver.switchTo().window(allhandles[allhandles.length - 1]);
 });

//should be use by xpath :(
let newtab = By.xpath('//*[@id="new_password"]');

await driver.wait(until.elementLocated(newtab));
await driver.wait(until.elementIsVisible(driver.findElement(newtab))).sendKeys('Tester123!!');
//enter confirm password
await driver.findElement(By.xpath('//*[@id="confirmpass"]')).sendKeys('Tester123!!');
现在一切都好了。快乐编码