Selenium启动Chrome时配置选项

2023-11-18

Selenium操作浏览器是不加载任何配置的,网上找了半天,关于Firefox加载配置的多点,Chrome资料很少,下面是关于加载Chrome配置的方法:
   一、加载所有Chrome配置
  用Chrome地址栏输入chrome://version/,查看自己的“个人资料路径”,然后在浏览器启动时,调用这个配置文件,代码如下:
  #coding=utf-8
  from selenium import webdriver
  option = webdriver.ChromeOptions()
  option.add_argument('--user-data-dir=C:\Users\Administrator\AppData\Local\Google\Chrome\User Data') #设置成用户自己的数据目录
  driver = webdriver.Chrome(chrome_options=option)
   二、修改浏览器的User-Agent来伪装你的浏览器访问手机m站
  #coding=utf-8
  from selenium import webdriver
  option = webdriver.ChromeOptions()
  option.add_argument('--user-agent=iphone')
  driver = webdriver.Chrome(chrome_options=option)
  driver.get('http://www.taobao.com/')
   三、浏览器启动时安装crx扩展
  #coding=utf-8
  from selenium import webdriver
  option = webdriver.ChromeOptions()
  option.add_extension('d:\crx\AdBlock_v2.17.crx') #自己下载的crx路径
  driver = webdriver.Chrome(chrome_options=option)
  driver.get('http://www.taobao.com/')

  可以去https://sites.google.com/a/chromium.org/chromedriver/capabilities查看更多,或者去http://stackoverflow.com/查找。

下边是收集的一些配置信息:
  一些Chrome的地址栏命令(这些命令会不停的变动,所有不一定都是好用的)
  在Chrome的浏览器地址栏中输入以下命令,就会返回相应的结果。这些命令包括查看内存状态,浏览器状态,网络状态,DNS服务器状态,插件缓存等等。
  about:version - 显示当前版本
  about:memory - 显示本机浏览器内存使用状况
  about:plugins - 显示已安装插件
  about:histograms - 显示历史记录
  about:dns - 显示DNS状态
  about:cache - 显示缓存页面
  about:gpu -是否有硬件加速
  about:flags -开启一些插件 //使用后弹出这么些东西:“请小心,这些实验可能有风险”,不知会不会搞乱俺的配置啊!
  chrome://extensions/ - 查看已经安装的扩展
  其他的一些关于Chrome的实用参数及简要的中文说明(使用方法同上,当然也可以在shell中使用)
  –user-data-dir=”[PATH]” 指定用户文件夹User Data路径,可以把书签这样的用户数据保存在系统分区以外的分区。
  –disk-cache-dir=”[PATH]“ 指定缓存Cache路径
  –disk-cache-size= 指定Cache大小,单位Byte
  –first run 重置到初始状态,第一次运行
  –incognito 隐身模式启动
  –disable-javascript 禁用Javascript
  --omnibox-popup-count="num" 将地址栏弹出的提示菜单数量改为num个。我都改为15个了。
  --user-agent="xxxxxxxx" 修改HTTP请求头部的Agent字符串,可以通过about:version页面查看修改效果
  --disable-plugins 禁止加载所有插件,可以增加速度。可以通过about:plugins页面查看效果
  --disable-javascript 禁用JavaScript,如果觉得速度慢在加上这个
  --disable-java 禁用java
  --start-maximized 启动就最大化
  --no-sandbox 取消沙盒模式
  --single-process 单进程运行
  --process-per-tab 每个标签使用单独进程
  --process-per-site 每个站点使用单独进程
  --in-process-plugins 插件不启用单独进程
  --disable-popup-blocking 禁用弹出拦截
  --disable-plugins 禁用插件
  --disable-images 禁用图像
  --incognito 启动进入隐身模式
  --enable-udd-profiles 启用账户切换菜单
  --proxy-pac-url 使用pac代理 [via 1/2]
  --lang=zh-CN 设置语言为简体中文
  --disk-cache-dir 自定义缓存目录
  --disk-cache-size 自定义缓存最大值(单位byte)
  --media-cache-size 自定义多媒体缓存最大值(单位byte)
  --bookmark-menu 在工具 栏增加一个书签按钮
  --enable-sync 启用书签同步
以下是转自 http://alanland.iteye.com/blog/604013

常用:

–single-process 单进程运行Google Chrome

–start-maximized 启动Google Chrome就最大化

–disable-java 禁止Java

–no-sandbox  非沙盒模式运行

 

 

全部:(下面的没有进行翻译,仔细看下应该都看得懂. ~ ~)

–disable-hang-monitor

Suppresses hang monitor dialogs in renderer processes.

–disable-metrics

Completely disables UMA metrics system.

–disable-metrics-reporting

Disables only the sending of metrics reports. In contrast to kDisableMetrics, this executes all the code that a normal client would use for reporting, except the report is dropped rather than sent to the server. This is useful for finding issues in the metrics code during UI and performance tests.

–assert-test

Causes the browser process to throw an assertion on startup.

–renderer-assert-test

Causes the renderer process to throw an assertion on launch.

–crash-test

Performs a crash test when the browser is starte.

–renderer-crash-test

Causes the renderer process to crash on launch.

–renderer-startup-dialog

Use this argument when you want to see the child processes as soon as Chrome start.

–plugin-startup-dialog

Causes the plugin process to display a dialog on launch.

–testshell-startup-dialog

Causes the test shell process to display a dialog on launch.

–plugin-launcher

Specifies a command that should be used to launch the plugin process. Useful

for running the plugin process through purify or quantify. Ex:

–plugin-launcher=”path\to\purify /Run=yes.

–plugin-launche.

–channel

The value of this switch tells the child process which

IPC channel the browser expects to use to communicate with it.

–testing-channel

The value of this switch tells the app to listen for and broadcast

testing-related messages on IPC channel with the given ID.

–homepage

The value of this switch specifies which page will be displayed

in newly-opened tabs. We need this for testing purposes so

that the UI tests don’t depend on what comes up for http://google.com.

–start-renderers-manually

When this switch is present, the browser will throw up a dialog box

asking the user to start a renderer process independently rather

than launching the renderer itself. (This is useful for debugging..

–renderer

Causes the process to run as renderer instead of as browser.

–renderer-path

Path to the executable to run for the renderer subproces.

–plugin

Causes the process to run as plugin hos.

–single-process

Runs the renderer and plugins in the same process as the browse.

–process-per-tab

Runs each set of script-connected tabs (i.e., a BrowsingInstance) in its own

renderer process. We default to using a renderer process for each

site instance (i.e., group of pages from the same registered domain with

script connections to each other).

–process-per-site

Runs a single process for each site (i.e., group of pages from the same

registered domain) the user visits. We default to using a renderer process

for each site instance (i.e., group of pages from the same registered

domain with script connections to each other).

–in-process-plugins

Runs plugins inside the renderer proces.

–no-sandbox

Runs the renderer outside the sandbox.

–safe-plugins

Runs the plugin processes inside the sandbox.

–trusted-plugins

Excludes these plugins from the plugin sandbox.

This is a comma separated list of plugin dlls name and activex clsid.

–test-sandbox

Runs the security test for the sandbox.

–user-data-dir

Specifies the user data directory, which is where the browser will look

for all of its state.

–app

Specifies that the associated value should be launched in “application” mode.

–upload-file

Specifies the file that should be uploaded to the provided application. This

switch is expected to be used with –app option.

–dom-automation

Specifies if the dom_automation_controller_ needs to be bound in the

renderer. This binding happens on per-frame basis and hence can potentially

be a performance bottleneck. One should only enable it when automating

dom based tests.

–plugin-path

Tells the plugin process the path of the plugin to loa.

–js-flags

Specifies the flags passed to JS engin.

–geoid

The GeoID we should use. This is normally obtained from the operating system

during first run and cached in the preferences afterwards. This is a numeric

value; see http://msdn.microsoft.com/en-us/library/ms776390.aspx .

–lang

The language file that we want to try to open. Of the form

language[-country] where language is the 2 letter code from ISO-639.

–debug-children

Will add kDebugOnStart to every child processes. If a value is passed, it

will be used as a filter to determine if the child process should have the

kDebugOnStart flag passed on or not.

–debug-on-start

Causes the process to start the JIT debugger on itself (mainly used by –debug-children.

–wait-for-debugger-children

Will add kWaitForDebugger to every child processes. If a value is passed, it

will be used as a filter to determine if the child process should have the

kWaitForDebugger flag passed on or not.

–wait-for-debugger

Waits for a debugger for 60 second.

–log-filter-prefix

Will filter log messages to show only the messages that are prefixed

with the specified valu.

–enable-logging

Force logging to be enabled. Logging is disabled by default in release

builds.

–dump-histograms-on-exit

Dump any accumualted histograms to the log when browser terminates (requires

logging to be enabled to really do anything). Used by developers and test

scripts.

–disable-logging

Force logging to be disabled. Logging is enabled by default in debug

builds.

–log-level

Sets the minimum log level. Valid values are from 0 to 3:

INFO = 0, WARNING = 1, LOG_ERROR = 2, LOG_FATAL = 3.

–remote-shell-port

Enable remote debug / automation shell on the specified por.

–uninstall

Runs un-installation steps that were done by chrome first-run.

–omnibox-popup-count

Number of entries to show in the omnibox popup.

–uninstallomnibox-popup-count

Removes the previous set suggestion coun.

–automation-channel

The value of this switch tells the app to listen for and broadcast

automation-related messages on IPC channel with the given ID.

–restore-last-session

Indicates the last session should be restored on startup. This overrides

the preferences value and is primarily intended for testing.

–record-mode

–playback-mode

Chrome supports a playback and record mode. Record mode saves *everything*

to the cache. Playback mode reads data exclusively from the cache. This

allows us to record a session into the cache and then replay it at will.

–no-events

Don’t record/playback events when using record & playback.

–hide-icons

–show-icons

Make Windows happy by allowing it to show “Enable access to this program”

checkbox in Add/Remove Programs->Set Program Access and Defaults. This

only shows an error box because the only way to hide Chrome is by

uninstalling it.

–make-default-browser

Make Chrome default browse.

–proxy-server

Use a specified proxy server, overrides system settings. This switch only

affects HTTP and HTTPS requests.

–dns-log-details

–dns-prefetch-disable

Chrome will support prefetching of DNS information. Until this becomes

the default, we’ll provide a command line switch.

–debug-print

Enables support to debug printing subsystem.

–allow-all-activex

Allow initialization of all activex controls. This is only to help website

developers test their controls to see if they are compatible in Chrome.

Note there’s a duplicate value in activex_shared.cc (to avoid

dependency on chrome module). Please change both locations at the same time.

–disable-dev-tools

Browser flag to disable the web inspector for all renderers.

–always-enable-dev-tools

Enable web inspector for all windows, even if they’re part of the browser.

Allows us to use our dev tools to debug browser windows itself.

–memory-model

Configure Chrome’s memory model.

Does chrome really need multiple memory models? No. But we get a lot

of concerns from individuals about how the changes work on *their*

system, and we need to be able to experiment with a few choices.

–tab-count-to-load-on-session-restore

Used to set the value of SessionRestore::num_tabs_to_load_. See session_restore.h for details.

const wchar_t kTabCountToLoadOnSessionRestore[] .

–memory-profile

Enable dynamic loading of the Memory Profiler DLL, which will trace

all memory allocations during the run.

–enable-file-cookies

By default, cookies are not allowed on file://. They are needed in for

testing, for example page cycler and layout tests. See bug 1157243.

–start-maximized

Start the browser maximized, regardless of any previous settings.

TODO(pjohnson): Remove this once bug 1137420 is fixed. We are using this

as a workaround for not being able to use moveTo and resizeTo on a

top-level window.

–enable-watchdog

Spawn threads to watch for excessive delays in specified message loops.

User should set breakpoints on Alarm() to examine problematic thread.

Usage: -enable-watchdog=[ui][io]

Order of the listed sub-arguments does not matter.

–first-run

Display the First Run experience when the browser is started, regardless of

whether or not it’s actually the first run.

–message-loop-strategy

–message-loop-histogrammer

Enable histograming of tasks served by MessageLoop. See about:histograms/Loop

for results, which show frequency of messages on each thread, including APC

count, object signalling count, etc.

–import

Perform importing from another browser. The value associated with this

setting encodes the target browser and what items to import.

–silent-dump-on-dcheck

Change the DCHECKS to dump memory and continue instead of crashing.

This is valid only in Release mode when –enable-dcheck is specified.

–disable-prompt-on-repost

Normally when the user attempts to navigate to a page that was the result of

a post we prompt to make sure they want to. This switch may be used to

disable that check. This switch is used during automated testing.

–disable-popup-blocking

Disable pop-up blocking.

–disable-javascript

Don’t execute JavaScript (browser JS like the new tab page still runs).

–disable-java

Prevent Java from running.

–disable-plugins

Prevent plugins from running.

–disable-images

Prevent images from loading.

–use-lf-heap

Use the low fragmentation heap for the CRT.

–gears-plugin-path

Debug only switch to specify which gears plugin dll to load.

–gears-in-renderer

Switch to load Gears in the renderer process.

–enable-p13n

–javascript-debugger-path

Allow loading of the javascript debugger UI from the filesystem.

–new-http

Enable new HTTP stack.


本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Selenium启动Chrome时配置选项 的相关文章

随机推荐

  • 因果推断----do演算

    do演算 合法 的do表达式变换 规则1 如果我们观察到变量W与Y无关 其前提可能是以其他变量Z为条件 那么Y的概率分布就不会随W而改变 即 P Y d
  • vue3+elementPlus-浏览器告警解决error.ts:14 ElementPlusError: [ElPagination] 你使用了一些已被废弃的用法,请参考 el-pagination

    问题 在使用elementuiPlus的分页器组件的时候 发现会有如下图警告 检查代码
  • 微信小程序父组件向子组件传参,子组件样式无效问题处理

    微信小程序父组件向子组件传参 子组件样式无效问题处理 父组件代码 引入 json usingComponents evaluate evaluate evaluate wxml
  • dp 1.4协议_浅析关于HDMI接口与DP接口

    显示器现在主流已经为HDMI接口与DP接口 那么这些接口都有什么区别 以下表格会大致做个区分 建议优先使用DP接口 HDMI2 1接口目前仅发布协议 尚未大规模商用在高清电视机上有部分应用 Mini DP接口版本为DP1 2 HDMI2 1
  • libcurl库安装心得

    一 libcurl简介 libcurl是一个跨平台的网络协议库 支持http https ftp gopher telnet dict file 和ldap 协议 libcurl同样支持HTTPS证书授权 HTTP POST HTTP PU
  • JSON工具类

    在实际开发中通服都是使用JSON格式数据 那么如何跟JSON打交道呢 下面就写一些JSON的常用转换工具 以及JSON数据提取 目录 阿里的FastJSON JSONObject类 JSON类 JSONArray JSONPath Json
  • 分子对接教程

    TCGA GEO 文献阅读 数据库 理论知识 R语言 Bioconductor 服务器与Linux 接前文 分子对接教程 1 软件安装准备 分子对接教程 2 选择合适的蛋白受体 分子对接教程 3 配体分子文件格式转换 分子对接教程 4 蛋白
  • QT 中文版信息提示框

    引言 在QT设计UI程序过程中 整套系统都是中文版本 然而信息提示默认只有中文 难免有点小纠结 这里针对QMessageBox稍微做了一点点改进 使其支持完美的中文提示框 调用方式非常简单 只需要将QMessageBox调用地方 改为QSh
  • 专家PID

    专家PID 专家控制 专家控制是模拟人类专家控制的方式 它具有大量的专门知识和经验 和专家控制一样不需要知道对象的模型的情况下 对系统进行控制 专家控制的基本结构 和人类专家控制一样 知识库越是丰富 推理机越是精确 控制效果也就越好 不同的
  • 数据结构C++ 栈Stack求值算法

    来自邓俊辉老师的数据结构 C 版 第95页 readNumber函数 可读整数和小数 注意 下列代码是直接用C 内部写好的stack实现的 而不是书中给出的stack模板 发现更简洁的readNumber函数 float readNumbe
  • 使用Vue解决跨域问题

    如果你是一个Web前端工程师 那么跨域这个问题肯定是绕不开的 1 创建 vue config js 设置 devServer 属性 module exports devServer webpack dev server配置 host loc
  • ECS共享型s6和ECS突发性能型t6的区别选择哪个好?

    WP建站 一个专注于wordpress学习的 关注他 2 人赞同了该文章 这两个类型的阿里云ecs服务器的话 一般在这两个中二选一的话我们建议优先选择ECS共享型s6 我们简单的来说说他们的一些区别和特点吧 首先我们要知道的是他们都是独立的
  • 线性代数-----行列式的性质

    行列式的性质 设 D a 11
  • cosmos测试网络结点搭建完整流程

    第一步 下载golang并安装 配置环境变量 wget https dl google com go go1 13 8 linux amd64 tar gz tar C usr local xzf go VERSION OS ARCH ta
  • CSDN周赛66期图文题解 - 路灯亮度 & 池塘水量

    本期非编程题考察更多是对原书的阅读理解 可能还是因为自己理解不够 翻了半天书 还是错了两道 失之我命 不多废话 本期编程题比较符合我的胃口 有陷阱 有技巧 窃以为是最近不少期里比较有意思的中等难度的题目了 美中不足的是两道题都没有给出数据范
  • 读写权限详解

    本篇博客主要通过三个问题来理清C C 中的读写权限问题 const变量可以赋值给非const引用吗 const变量的地址可以赋值给非const指针吗 const普通变量可以给非const普通变量赋值吗 在此之前 我们得先明白读写权限的一个基
  • 利用原始socket简单实现FTP的客户端和服务器端程序

    1 设计目的 本设计旨在利用原始socket简单实现FTP File Transfer Protocol 文件传输协议 的客户端和服务器端程序 能够实现get put pwd dir cd等基本交互命令 2 具体要求 用socket 编程接
  • C# 去掉图片多余白色部分

  • AOI的实际应用

    使用AOI检测LED固晶焊线的支架产品 产品结构 使用远心光学镜头 高分辨率 高景深 低畸变以及独有的平行光设计等 被测元件清晰成像 且无斜视 保证不良检出 1 缺陷检测原理 通过模板匹配法 这是一种基本的识别方法 研究某一特定对象物的图案
  • Selenium启动Chrome时配置选项

    Selenium操作浏览器是不加载任何配置的 网上找了半天 关于Firefox加载配置的多点 Chrome资料很少 下面是关于加载Chrome配置的方法 一 加载所有Chrome配置 用Chrome地址栏输入chrome version 查