提问人:Karina Campanharo 提问时间:7/26/2023 最后编辑:fabrikKarina Campanharo 更新时间:7/27/2023 访问量:13
sendkeys 不适用于非“file”类型的字段 - 带有 Nodejs 的 selenium
sendkeys not working on a field that is not of type 'file' - selenium with Nodejs
问:
我正在尝试使用 Selenium 和 JavaScript 自动化一个字段,我必须在测试中从我的屏幕发送一个文件。但是,发送文件的字段不是“File”类型,并且 sendkeys() 方法不起作用。在我的 HTML 下面:
xpath=//button\[@id='id-ff3923ce-1732-4337-911e-75e0d718fc8a-36-notescontrol-attachment_action'\]/span
这是我应该将文件发送到的元素。这是一个按钮。我不知道如何解决这个问题,有人可以帮我吗?
我尝试运行下面的代码,但错误是:
erro ElementNotInteractableError: element not interactable
(Session info: chrome=114.0.5735.248)
at Object.throwDecodedError (C:\Users\SRV_GHQ_ITSEngQA\Desktop\mocha_selenium\node_modules\selenium-webdriver\lib\error.js:524:15)
at parseHttpResponse (C:\Users\SRV_GHQ_ITSEngQA\Desktop\mocha_selenium\node_modules\selenium-webdriver\lib\http.js:601:13)
at Executor.execute (C:\Users\SRV_GHQ_ITSEngQA\Desktop\mocha_selenium\node_modules\selenium-webdriver\lib\http.js:529:28)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async thenableWebDriverProxy.execute (C:\Users\SRV_GHQ_ITSEngQA\Desktop\mocha_selenium\node_modules\selenium-webdriver\lib\webdriver.js:745:17)
at async GrPage.file (C:\Users\SRV_GHQ_ITSEngQA\Desktop\mocha_selenium\pageobjects\Grpage.js:120:7)
at async Context.<anonymous> (C:\Users\SRV_GHQ_ITSEngQA\Desktop\mocha_selenium\test\GRTest.js:85:9) {
remoteStacktrace: 'Backtrace:\n' +
async file(){
try {
const filePath = '../resources/qa.jpg';
let fileInput = await driver.wait(until.elementLocated(By.css(".Attach-symbol")));
await driver.wait(until.elementIsVisible(fileInput), 5000);
await driver.wait(until.elementIsEnabled(fileInput), 5000);
await fileInput.sendKeys(filePath);
} catch (error) {
console.log("erro ", error)
}
}
答: 暂无答案
评论