c# - Selenium 设置偏好目录

标签 c# firefox selenium webdriver selenium-webdriver

我正在使用 firefox webdriver。我想将所有 cookie 和缓存文件存储到一个自定义目录中。但它采用临时目录而不是我的目录。这是我的代码:

FirefoxProfile firefoxProfile = new FirefoxProfile(path, false);
MessageBox.Show(firefoxProfile.ProfileDirectory);     //Its showing blank
driver = new FirefoxDriver(firefoxProfile);
MessageBox.Show(firefoxProfile.ProfileDirectory);    //Its showing the temp dir
                                                     //not my custom dir

如何让它获取我的目录并将所有 cookie 和文件存储在那里?

谢谢。

编辑:

我需要修复 selenium 配置文件目录(因为它一直在变化)。这样我就可以使用以前的 cookie 和缓存文件。你能给我任何想法或任何替代方法来完成它吗?

最佳答案

您可以直接找到临时文件路径,然后在创建驱动程序后使用系统命令将文件复制到此文件夹中。然后你就可以访问它们了,虽然这有点 hacky 但应该可以工作(除非我在这里错过了一些重要的东西,我觉得我可能有 :) )

关于c# - Selenium 设置偏好目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10375961/

相关文章:

firefox - 仅 Firefox 的 SSL 安全证书无效

java - 数据库问题

c# - 找到足够远的位置

c# - 启动应用程序时有时会出现 FileNotFoundException

firefox - F5 负载平衡器和 Fortigate 200d 防火墙之间的 TLSv1.2 问题 - SSL 错误 Bad MAC Read

firefox - 在 Selenium IDE 中关闭新打开的选项卡或窗口

java - 在 TestNG 中多次使用一个类

python - 无法通过链接使用查找元素定位

c# - C#音频库-WMP或其他

c# - 以编程方式为 Windows 搜索服务创建目录