When running WebDriver (Ruby) using Chrome, what are the specific command-line switches or desired_capabilities to disable Chrome's built-in PDF viewer.
In other words, how does one programmatically configure Chrome to download PDF files rather than open using its internal PDF-viewer plugin?
Updated answer: Chrome 61 : Ruby 2.3 : ChromeDriver 2.32.498537
download_prefs = {
prompt_for_download: false,
default_directory: 'desired/download/path'
}
plugin_prefs = {
always_open_pdf_externally: true
}
options = Selenium::WebDriver::Chrome::Options.new
options.add_preference(:download, download_prefs)
options.add_preference(:plugins, plugin_prefs)
driver = Selenium::WebDriver.for :chrome, options: options
Based on the following resource provided Save PDF instead of opening in Selenium, I found this worked as desired
prefs = {
plugins: {
plugins_disabled: ['Chrome PDF Viewer']
},
download: {
prompt_for_download: false,
directory_upgrade: true,
default_directory: 'desired/download/path'
}
}
browser = Selenium::WebDriver.for :chrome, prefs: prefs
There must be no trailing slash in the directory path
Related
I am unable to use specific profile in Puppeteer. It always open the chrome as a new user.
For example: I have 3 profiles for my chrome. Following is the code I am using to open chrome in specific profile:
const browser = await puppeteer.launch({
headless: false,
executablePath: 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe',
// args: ['--profile-directory="Profile 1"'],
userDataDir:"C:\\Users\\USER_NAME\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 1"
});
But it always open the chrome as "Current user" profile.
Try below code:
const browser = await puppeteer.launch({headless:false, args:[
'--user-data-dir=/user/data/directory/profile_n']
});
Full explanation is given here:
In Puppeteer how to switch to chrome window from default profile to desired profile
Nowadays this should work with:
args: ['--profile-directory="Profile 1"'],
userDataDir:"C:\\Users\\USER_NAME\\AppData\\Local\\Google\\Chrome\\User Data"
I want to run a basic script that takes a screenshot of the tv schedule each day on a specific url, the url in question has a cookies pop up that requests to be accepted before the rest of the page is displayed, this obviously gets in the way of my intended screenshot, a similar post (Pupeteer - how can I accept cookie consent prompts automatically for any URL?) had a solution that suggested to download the chrome extension 'I don't care about cookies' and then run puppeteer with google chrome with this extension installed, I have installed the extension and ran puppeteer with chrome but the extension does not seem to show up in the chrome window that puppeteer creates, how do I fix this so the extension is there when I run chrome using puppeteer? note: I am intentionally using regular chrome not chromium for this reason, chromium does not allow extensions with puppeteer.
my code:
const puppeteer = require('puppeteer-core')
async function main() {
const browser = await puppeteer.launch({
headless: false,
slowMo:10,
executablePath: '/Applications/Google
Chrome.app/Contents/MacOS/Google Chrome',
args: [
'--disable-extensions-except=/Applications/Google
Chrome.app/Contents/MacOS/Google Chrome',
'--load-extension=/Applications/Google
Chrome.app/Contents/MacOS/Google Chrome',
]
});
const page = await browser.newPage()
await page.setViewport({
width: 980,
height: 480,
deviceScaleFactor: 2,
});
await
page.goto("https://www.tvguide.co.uk/mobile/channellisting.asp?
ch=145#588622936")
await page.waitForTimeout(15000); // wait for 15 seconds
await browser.close()
}
main();
Any reply would be greatly appreciated. Many Thanks.
I’ve been trying without success to change default language of browsers Chromium and Firefox (inside automated tests that run in parallel using CodeceptJS + Playwright as runner) to french language. In Chromium, I’ve tried to use args --lang without success and I’ve also tried to use prefs: intl.accept_languages. In Firefox, I’ve tried to use firefoxUserPrefs. Untill now, nothing has worked.
Does anybody know how to change default language in browser launched using playwright?
CodeceptJS version 3.0.6
Playwright version 1.10.0
Chrome version 90.0.4430.0
Firefox version 87.0b10
codecept.conf.js - full printscreen
codecept.conf.js
Playwright: {
url: process.env.baseUrl || DEFAULT_HOST,
show: true,
browser: 'chromium',
waitForAction: 250,
waitForNavigation: 'networkidle0',
chromium: {
channel: process.env.BROWSER,
args: ['--lang=fr-CA'],
prefs: {
'intl.accept_languages': 'fr-CA',
},
firefoxUserPrefs: {
'intl.accept_languages': 'fr-CA, fr',
},
},
},
browser.NewContext has an option called locale. You can use that option to change the language.
This might not have been available by the time of this question, but now there are emulation options for locale (and timezone) in Playwright (documentation here).
Can be specified both globally in config, per project, like this (in playwright.config.ts):
...
projects: [
{
name: 'chromium',
use: {
...devices['Desktop Chrome'],
locale: 'fr-CA',
},
},
...
or per test, like this:
test.use({
locale: 'sv-SE',
});
test('Lang test 1', async ({ page }) => {
// Test code
});
Is used the two packag.json structure to load dependencies in electron builder config.
"build": {
"asar": true,
"asarUnpack": "node_modules/puppeteer/.local-chromium/**/*",
"appId": "client.zpa",
"directories": {
"output": "./dist-exec",
"app": "."
},
"win": {
"target": [
{
"target": "nsis",
"arch": [ "ia32" ]
}
]
},
"nsis": {
"artifactName": "${productName}_${version}1231.${ext}"
}
...
"dependencies": {
"serial-number": "1.3.0",
"puppeteer": "~1.15.0",
"hummus": "~1.0.104"
}
in dist/node_modules/puppeteer the folder .local-chromium is missing. Any ideas how I can force installing local chromium?
I had the same problem.
Solved via downloading chromium according to current OS (Windows/Linux/Mac OS) on first start.
And, if there is Google Chrome browser available on running machine, you can pass path to chromium in puppeteer config.
Something like this on Windows C:\Program Files (x86)\Google\Chrome\Application\chrome.exe or run this
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -dump | grep -i "google chrome"
on Mac OS to find path to Google Chrome.
I've heard that it is possible to use Electron IPC and that calls into the JavaScript boot file and then run puppeteer from there.
But haven't tried.
After 2 days of searching on StackOverflow and GitHub issues, I found that no actual solutions to build the local chrome with the electron app the best solution was to set the executable path and use chrome installed on the pc but many answers said that You will do it manually but I found this better to do it using "chrome-path" npm package to set path of chrome auto in mac or Linux or Windows here it's my code background.js
const puppeteer = require("puppeteer")
const chromePaths = require('chrome-paths');
//your electron init window
const browser = await puppeteer.launch({
executablePath:chromePaths.chrome,
headless: false,
defaultViewport: null,
args: ['--no-sandbox', '--start-maximized' ],
slowMo:25,
})
const page = await browser.newPage();
await page.goto("https://google.com")
await app(page)
`
Need help with below issues. I have work around for issue 1 so any tips on issue 2 would be great:
--start-maximized won't trigger full window so my current work around is adding below line in beforeEach function:
browser.driver.manage().window().maximize();
Trying to download file to default directory but the file is just going to download folder on my C drive instead of /tmp/downloads (on another drive).
My config:
capabilities: {
'browserName': 'chrome',
'chromeOption': {
args: ['--lang=en', '--start-maximized'],
prefs: {
'download': {
'prompt_for_download': false,
'default_directory': '/tmp/downloads',
},
},
},
},
As for download, I'm currently using solution from here.
There is a typo. It should be chromeOptions, not chromeOption.
I think the options in protractor conf have been updated to be without "--".
So perhaps try without "--"?
args: ['lang=en', 'start-maximized']