123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- const webdriver = require('selenium-webdriver');
- const { Options } = require('selenium-webdriver/chrome');
- const caps = webdriver.Capabilities.chrome();
- caps.set('chromeOptions', { 'excludeSwitches': ['enable-automation'] })
- caps.set('prefs', { "profile.managed_default_content_settings.images": 2 })
- const options = new Options();
- options.setChromeBinaryPath('C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe');
- const userName = '18683971105';
- const password = 'chengrang.'
- async function initDriver() {
- let driver = new webdriver.Builder()
- .setChromeOptions(options)
- .withCapabilities(caps)
- .build();
- driver.executeScript(()=>{
- Object.defineProperty(navigator, 'webdriver', {get: () => undefined});
- })
- await driver.get('https://login.taobao.com/')
-
- const initWindow = await driver.getWindowHandle();
-
-
-
- await driver.sleep(1000)
- const accountEle = await driver.findElement(webdriver.By.xpath('//*[@id="fm-login-id"]'));
- const passwordEle = await driver.findElement(webdriver.By.xpath('//*[@id="fm-login-password"]'));
- const submitBtn = await driver.findElement(webdriver.By.xpath('//*[@id="login-form"]/div[4]/button'));
- await accountEle.sendKeys(userName)
- await passwordEle.sendKeys(password);
- await submitBtn.click();
- return {
- driver,
- initWindow
- }
- }
- initDriver();
- module.exports = initDriver;
|