有时无效参数错误:'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)        
} 

相关内容

  • 没有找到相关文章

最新更新