首页 > 解决方案 > “API 命令登录表单”中的无效元素状态

问题描述

我是 Selenium Webdriver 的新手

我试过这段代码

    const uName = $('[data-bn-type="input"]');
    uName.waitForDisplayed({ timeout: 10000 });
    uName.setValue("tomsmith@mkdsz.site");

    const pWord = $('[name="password"]');
    pWord.waitForDisplayed({ timeout: 10000 });
    pWord.setValue("SuperSecretPassword!");

    const lBtn = $('[type="flatprimary"]');
    lBtn.waitForDisplayed({ timeout: 3000 });
    lBtn.click();

当我用谷歌浏览器的控制台测试选择器时,它起作用了!但是当我尝试使用硒时,它显示了这个错误

[0-0] invalid element state in "API Command Login Form"
invalid element state
  (Session info: chrome=91.0.4472.124)
    at Object.getErrorFromResponseBody (E:\Automate with JS\Practice\Phan_2\node_modules\webdriver\build\utils.js:189:12)
    at WebDriverRequest._request (E:\Automate with JS\Practice\Phan_2\node_modules\webdriver\build\request.js:168:31)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async Element.elementErrorHandlerCallbackFn (E:\Automate with JS\Practice\Phan_2\node_modules\webdriverio\build\middlewares.js:23:32)
    at async Element.setValue (E:\Automate with JS\Practice\Phan_2\node_modules\webdriverio\build\commands\element\setValue.js:30:5)
    at async Element.runCommandWithHooks (E:\Automate with JS\Practice\Phan_2\node_modules\@wdio\sync\build\wrapCommand.js:105:25)
    at Element.runCommandWithHooks (E:\Automate with JS\Practice\Phan_2\node_modules\@wdio\sync\build\wrapCommand.js:100:24)
    at Element.wrapCommandFn (E:\Automate with JS\Practice\Phan_2\node_modules\@wdio\sync\build\wrapCommand.js:67:44)
    at Element.elementErrorHandlerCallback (E:\Automate with JS\Practice\Phan_2\node_modules\webdriverio\build\middlewares.js:44:12)
    at Context.<anonymous> (E:\Automate with JS\Practice\Phan_2\test_scripts\LoginForm.js:9:11)    
    at Context.executeSync (E:\Automate with JS\Practice\Phan_2\node_modules\@wdio\sync\build\index.js:38:22)
    at E:\Automate with JS\Practice\Phan_2\node_modules\@wdio\sync\build\index.js:69:68

谁能帮我这个?谢谢!

标签: javascriptseleniumselenium-webdriverwebdriverselenium-chromedriver

解决方案


推荐阅读