我想知道用打字稿中的selenium-webdriver处理远程文件上传的方式是什么?
在javascript中,这段代码有效:
import remote from 'selenium-webdriver/remote';
// import * as remote from 'selenium-webdriver/remote'; // used for typescript
browser.setFileDetector(new remote.FileDetector());
uploadElement.sendKeys(path.resolve(__dirname, f));
但是在打字稿中,我得到了Property 'FileDetector' does not exist on type 'typeof remote'
。我已经安装了@types/selenium-webdriver
和selenium-webdriver
。
"@types/selenium-webdriver": "^2.53.39",
"selenium-webdriver": "^3.0.1"
修改:根据bcherny的建议进行更新
import { FileDetector } from 'selenium-webdriver';
return fileDetector.handleFile(browser.driver, f).then((fPath) => {
browser.setFileDetector(fileDetector);
return uploadElement.sendKeys(path.resolve(__dirname, fPath))
}
修改:工作代码
import * as remote from 'selenium-webdriver/remote';
browser.setFileDetector(new remote.FileDetector());
return uploadElement.sendKeys(path.resolve(__dirname, f))
答案 0 :(得分:1)
你想要
import { FileDetector } from 'selenium-webdriver'
答案 1 :(得分:0)
工作代码,必须从远程打字输入
import * as remote from 'selenium-webdriver/remote';
browser.setFileDetector(new remote.FileDetector());
return uploadElement.sendKeys(path.resolve(__dirname, f))