Typescript+Selenium 设置浏览器默认下载路径
import { WebDriver, Builder } from "selenium-webdriver";
import { Options, ServiceBuilder, setDefaultService } from "selenium-webdriver/chrome";
export const PATH="$PATH:/path/to/chromedriver"
export class SingleInstance{
private static instance: WebDriver;
public static create_driver() {
if(! this.instance) {
let chromePath: string = "./chrome/chrome.exe";
let chromeWebdriverPath:string = "./chrome/chromedriver.exe";
const environmentPath = 'D:\\Users\\Administrator\\Desktop\\Typescript-Selenium-PageObjecModelt\\src\\downloads';
let downloadPath = {"download.default_directory": `${environmentPath}`, "sagebrowsing.enabled": "false" };
setDefaultService(new ServiceBuilder(chromeWebdriverPath).build());
this.instance = new Builder().forBrowser("chrome")
.setChromeOptions(new Options().setChromeBinaryPath(chromePath).setUserPreferences(downloadPath))
.build()
}
return this.instance
}
}