javascript - 有时 InvalidArgumentError: 'handle' 必须是字符串
问题描述
我安装了“React-google-login”来响应项目。我正在编写一个应该绕过这个模块的自动测试。
try {
await driver.get("http://localhost:3000/");
await driver.wait(until.elementLocated(By.xpath(`//*[@id="root"]/div/button`)), 10000).click();
await driver.getAllWindowHandles().then(async function(handles){
await driver.switchTo().window(handles[1])
.then(async function(){ // ERROR: InvalidArgumentError: invalid argument: 'handle' must be a string
await driver.wait(until.elementLocated(By.id('identifierId')),20000).sendKeys('test@gmail.com', Key.ENTER)
await driver.wait(until.elementLocated(By.name('password')),20000).sendKeys('test1234', Key.ENTER) // ERROR: ElementNotInteractableError: element not interactable
});
});
} catch (e) {
console.log(e)
}
在某些情况下,代码可以满足,在某些情况下,错误是:
InvalidArgumentError: invalid argument: 'handle' must be a string
在某些情况下,错误是:
ElementNotInteractableError: element not interactable
请告诉我,我的代码有什么问题?
解决方案
这个解决方案决定了我的问题。
try {
await driver.get("http://localhost:3000/");
await driver.wait(until.elementLocated(By.xpath(`//*[@id="root"]/div/button/div`)), 10000) // wait this element
await driver.findElement(By.xpath(`//*[@id="root"]/div/button`)).click(); // -> after click on it
let winHandleBefore = driver.getWindowHandle(); // first window value
await driver.getAllWindowHandles().then(async function(handles){
await driver.switchTo().window(handles[1]).then(async function(){
await driver.wait(until.elementLocated(By.id('identifierId')),20000); // wait this element
await driver.findElement(By.id('identifierId')).sendKeys('test@gmail.com', Key.ENTER) // after input value
await driver.wait(until.elementLocated(By.name('password')),20000); // wait this element
await driver.findElement(By.name('password')).sendKeys('test1234', Key.ENTER) // after input value
});
});
driver.switchTo().window(winHandleBefore); // Change to the first window
await driver.wait(until.elementLocated(By.xpath(`//*[@id="root"]/div/img`)), 10000)
/* Any actions */
} catch (e) {
console.log(e)
}
推荐阅读
- android - 活动中的旧意图从通知开始
- angular - 如何使用 Observable 中的数据更新我的 Angular Table 数据源
- python - 国际开发协会 Python + Qt。如何将我自己的选项卡插入 IDA 主选项卡小部件?
- java - tls 正在使用自签名证书而不是真实证书的 mosquitto 经纪人
- vba - 将文本从一个词范围复制到另一个词的困难 - 返回错误代码“此命令不可用”
- android - 注册并使用注册号登录
- sql - 需要删除重复的名称
- sql - Oracle 加密/解密 clob
- html - 如何修复图像中的 CSS 和 Vue.js 错误?
- sas - 我在 SAS Model Studio 中训练了一个 Forest 模型。如何在 SAS Studio 中应用它?