如何使用WinAppDriver和Node输入文本?



下面是我的代码:

import { spawn } from 'child_process';
import { dirname } from 'path';
import { WindowsDriver } from 'appium-windows-driver';

async function main() {
const program = "C:\Program Files (x86)\Windows Application Driver\WinAppDriver.exe";
spawn(program, null, { cwd: dirname(program) });
const driver = new WindowsDriver();
await driver.createSession({
app: 'C:\Windows\System32\notepad.exe',
deviceName: 'WindowsPC',
platformName: 'Windows'
});
let element = await driver.findElement('xpath', '//*[@ClassName="Edit"]');
await element.type('Some text here...');
await driver.deleteSession();
process.exit();
}
await main();

这里是我的依赖项,也许我错过了安装一些东西?

"dependencies": {
"appium-windows-driver": "^1.19.0"
}

我不明白为什么我有这个TypeError:

TypeError: element.type is not a function

最后,我找到了怎么做。
但是有了selenium-appium和selenium-webdriver包。

import { dirname } from 'path';
import { spawn } from 'child_process';
import { driver, By2, windowsAppDriverCapabilities } from 'selenium-appium'
import { Key } from 'selenium-webdriver';

async function main() {
const program = 'C:/Program Files (x86)/Windows Application Driver/WinAppDriver.exe';
spawn(program, [], { cwd: dirname(program) });
const appExe = 'C:/Windows/System32/notepad.exe';
await driver.startWithCapabilities(windowsAppDriverCapabilities(appExe));
const element = By2.nativeXpath('//*[@ClassName="Edit"]');
await element.click();
await element.sendKeys('Some text here...');
await element.sendKeys(Key.CONTROL, 'a');
await element.sendKeys(Key.DELETE);
await driver.quit();
process.exit();
}
await main();

最新更新