nodejs selenium-webdriver 操作文檔
https://www.npmjs.com/package/selenium-webdriver
1.調(diào)用谷歌瀏覽器
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.調(diào)用火狐瀏覽器
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();
}
})();
下面設(shè)置了一些選項
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();
}
})();
?
需要設(shè)置環(huán)境變量,在CMD中firefox可以打開瀏覽器
否則報錯
Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOpti文章來源:http://www.zghlxwxcb.cn/news/detail-787657.html
?文章來源地址http://www.zghlxwxcb.cn/news/detail-787657.html
到了這里,關(guān)于selenium-webdriver調(diào)用谷歌瀏覽器和火狐瀏覽器的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!