<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Selenium &#8211; 李辉 / Grey Li</title>
	<atom:link href="https://greyli.com/tag/selenium/feed/" rel="self" type="application/rss+xml" />
	<link>https://greyli.com</link>
	<description>一个编程和写作爱好者的在线记事本</description>
	<lastBuildDate>Thu, 06 Nov 2025 11:36:11 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.9.26</generator>

<image>
	<url>https://greyli.com/wp-content/uploads/2025/03/avatar-500-compressed-144x144.jpg</url>
	<title>Selenium &#8211; 李辉 / Grey Li</title>
	<link>https://greyli.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>在Python Selenium中为Chrome和Firefox浏览器开启headless模式</title>
		<link>https://greyli.com/python-selenium-headless-for-chrome-firefox/</link>
		<comments>https://greyli.com/python-selenium-headless-for-chrome-firefox/#comments</comments>
		<pubDate>Sat, 28 Jul 2018 09:51:17 +0000</pubDate>
		<dc:creator><![CDATA[李辉]]></dc:creator>
				<category><![CDATA[技术笔记]]></category>
		<category><![CDATA[Chrome]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Selenium]]></category>

		<guid isPermaLink="false">http://greyli.com/?p=1814</guid>
		<description><![CDATA[我们通常会使用Selenium编写UI测试，为浏览器开启Headless模式（执行操作时不显示GUI窗口）会很 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>我们通常会使用Selenium编写UI测试，为浏览器开启Headless模式（执行操作时不显示GUI窗口）会很方便。最新版本的Chrome和Firefox中，均已支持headless模式。</p>
<p>在Selenium中，为这两个浏览器开启headless模式的方式基本相同：</p>
<p>Chrome：</p>
<pre class="">from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument('headless')
driver = webdriver.Chrome(options=options)</pre>
<p>Firefox：</p>
<pre class="">from selenium import webdriver

options = webdriver.FirefoxOptions()
options.add_argument('headless')
driver = webdriver.Firefox(options=options)</pre>
<p>我提交的PR<a href="https://github.com/SeleniumHQ/selenium/pull/5120" rel="noreferrer">#5120</a>添加了和Chrome相同的导入接口，如果你使用Selenium小于3.8.0版本，则需要将上面的<code>webdriver.FirefoxOptions()</code>替换为<code>webdriver.firefox.options.Options()</code>。</p>
<p>另外，你也可以使用环境变量<code>MOZ_HEADLESS</code> 来为Firefox开启headless模式：</p>
<pre class="">import os
from selenium import webdriver

os.environ['MOZ_HEADLESS'] = '1'  # &lt;- this line
driver = webdriver.Firefox()</pre>
<p>本文基于我在Stack Overflow的这篇回答：<a href="https://stackoverflow.com/a/47481793/5511849">https://stackoverflow.com/a/47481793/5511849</a></p>
]]></content:encoded>
			<wfw:commentRss>https://greyli.com/python-selenium-headless-for-chrome-firefox/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
