gpt4 book ai didi

javascript - NoSuchElementError : Unable to locate element - Selenium webdriver using Javascript 错误

转载 作者:行者123 更新时间:2023-11-29 23:15:55 30 4
gpt4 key购买 nike

因此,由于无数小时的研究,我知道了这个问题。唯一的问题是没有人像我一样基于他们的代码和/或不清楚在我的代码中插入的位置/内容。我知道您需要执行 try/catch 语句和/或执行 wait.until 语句。我都试过了都没有成功,非常感谢任何帮助。提前致谢!

require('chromedriver');
const selenium = require("selenium-webdriver");
const By = selenium.By;
const until = selenium.until;

const driver = new selenium.Builder().forBrowser("chrome").build();

driver.get("https://qa.chaplinq.org/LinQ/Account/SignIn");

const locators = {
loginForm: By.id("login-form"),
loginField: By.css("input#UserName"),
loginPass: By.css("#login-form input[name='Password']"),
signIn: By.css("form#login-form > footer > button"),
createAcc: By.css("a#createAccountBtn"),
applyfirstName: By.css("input#FirstName"),
applylastName: By.css("input#LastName"),

function createAcc() {
driver.findElement(locators.createAcc).click();

};

function firstName(text) {
driver.findElement(locators.applyfirstName).sendKeys(text);
};

createAcc();
firstName("kevin");

[ERROR] node : (node:1896) UnhandledPromiseRejectionWarning:
NoSuchElementError: no such element: Unable to
[ERROR] locate element: {"method":"css
selector","selector":"input#FirstName"}
[ERROR] At line:1 char:1
[ERROR] + node index.js
[ERROR] + ~~~~~~~~~~~~~
[ERROR] + CategoryInfo : NotSpecified: ((node:1896)
Unh...put#FirstName"}:String) [], RemoteExcepti
[ERROR] on
[ERROR] + FullyQualifiedErrorId : NativeCommandError
[ERROR]
[ERROR] (Session info: chrome=69.0.3497.100)
[ERROR] (Driver info: chromedriver=2.42.591088
(7b2b2dca23cca0862f674758c9a3933e685c27d5),platform=Windows NT
[ERROR] 10.0.17763 x86_64)
[ERROR] at Object.checkLegacyResponse
(C:\users\kevin.yu\node_modules\selenium-webdriver\lib\error.js:585:15)
[ERROR] at parseHttpResponse (C:\users\kevin.yu\node_modules\selenium-
webdriver\lib\http.js:533:13)
[ERROR] at Executor.execute (C:\users\kevin.yu\node_modules\selenium-
webdriver\lib\http.js:468:26)
[ERROR] at process._tickCallback (internal/process/next_tick.js:68:7)
[ERROR]
[ERROR] (node:1896) UnhandledPromiseRejectionWarning: Unhandled promise
rejection. This error originated either
[ERROR] by throwing inside of an async function without a catch block, or by
rejecting a promise which was not
[ERROR] handled with .catch(). (rejection id: 1)
[ERROR]
[ERROR] (node:1896) [DEP0018] DeprecationWarning: Unhandled promise
rejections are deprecated. In the future,
[ERROR] promise rejections that are not handled will terminate the Node.js
process with a non-zero exit code.
[ERROR]

最佳答案

“NoSuchElementError”表明该元素(还)不存在于 HTML 文档中。当某些元素动态出现/消失时,可能会发生这种情况。当您的 Selenium 脚本运行速度快于元素加载速度时,该元素尚不可见,将抛出此错误。

在您的情况下,元素 input#FirstName 是否仅在单击 input#FirstName 后出现?

如果是这样,请考虑添加 pausewait介于 createAcc() 和 firstName() 之间的函数

关于javascript - NoSuchElementError : Unable to locate element - Selenium webdriver using Javascript 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52772005/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com