nodejs selenium-webdriver 操作文档
https://www.npmjs.com/package/selenium-webdriver
1.调用谷歌浏览器
var DRIVER = require('selenium-webdriver');
var profile = DRIVER.Capabilities.chrome();
profile.set( 'browserName', 'chrome' );
profile.set('chromeOptions', {
'headless': true,
'args' : ['--lang=EN', '--disable-popup-blocking', '--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36' ]
});
var BUILDER = new DRIVER.Builder().withCapabilities( profile );
var BROWSER = BUILDER.build();
BROWSER.get('https://fpdk.yunnan.chinatax.gov.cn/');
2.调用火狐浏览器
const {Builder, By, Key, until} = require('selenium-webdriver');
(async function example() {
let driver = await new Builder().forBrowser('firefox').build();
try {
await driver.get('https://fpdk.yunnan.chinatax.gov.cn/');
} finally {
// await driver.quit();
}
})();
下面设置了一些选项
const {Builder, By, Key, until, Options} = require('selenium-webdriver');
const fs = require('fs');
const firefox = require('selenium-webdriver/firefox');
function waitTime(n) {
return new Promise(resolve => setTimeout(
() => resolve()
, n
))
}
(async function example() {
let options = new firefox.Options()
//options.headless()
let driver = await new Builder().forBrowser('firefox')
.setFirefoxOptions(options)
.build(options);
try {
await driver.get('https://fpdk.yunnan.chinatax.gov.cn/');
} finally {
//await driver.quit();
}
})();
需要设置环境变量,在CMD中firefox可以打开浏览器
否则报错
Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOpti文章来源:https://www.toymoban.com/news/detail-787657.html
文章来源地址https://www.toymoban.com/news/detail-787657.html
到了这里,关于selenium-webdriver调用谷歌浏览器和火狐浏览器的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!