为什么Selenium在使用Web Driver时总是创建临时的Firefox配置文件,即使我告诉它使用现有的配置文件?
根据这个答案,无法阻止Selenium使用Web Driver创建临时的Firefox配置文件。但是,使用chromedriver可以实现这一点。那么为什么Firefox不同呢?我检查了Selenium repo的FirefoxProfile.cs,并发现以下代码片段用于复制配置文件---
public void WriteToDisk()
{
this.profileDir = GenerateProfileDirectoryName();
if (!string.IsNullOrEmpty(this.sourceProfileDir))
{
FileUtilities.CopyDirectory(this.sourceProfileDir, this.profileDir);
}
else
{
Directory.CreateDirectory(this.profileDir);
}
this.InstallExtensions();
this.DeleteLockFiles();
this.DeleteExtensionsCache();
this.UpdateUserPreferences();
}
但是对于chrome来说,没有这样的事情。
是因为webdriver安装了一个扩展程序(webdriver.xpi)来与Firefox通信,而chromedriver.exe用于与Chrome交互。
如果这就是原因,在版本3.0中,webdriver正在使用geckodriver.exe与Firefox通信。因此,在版本3.0之后,webdriver将不再为Firefox创建临时配置文件?
更新: 今天我使用了webdriver v 3.0+并发现最新版本关闭legacymode仍会生成名为rust_mozprofile.wUqPXh48avDR的临时配置文件。我的猜测是这个临时配置文件是由geckodriver.exe生成的,它是用Rust编写的。
我在3年前使用过chromedriver,不确定 chromedriver.exe 是否也会生成这种类型的临时文件。期待专家的答案...
quit()
,它会删除临时文件夹--请参见 https://dev59.com/r2w15IYBdhLWcg3wJ4ms#30447335 - user202729