简体   繁体   English

如何使用修改后的 chromedriver 从 Nuget package 提供 Selenium?

[英]How to provide Selenium from Nuget package with modified chromedriver?

I'm very new to what I'm about to describe, so if there's a better way of going about this, please let me know.我对我将要描述的内容非常陌生,所以如果有更好的方法来解决这个问题,请告诉我。

I'm attempting to modify the source code for chromedriver, and use that modified version w/ Selenium's WebDriver.我正在尝试修改 chromedriver 的源代码,并使用带有 Selenium 的 WebDriver 的修改后的版本。 What I've done so far is gotten the source code for chromedriver from Chromium, modified, and compiled it.到目前为止,我所做的是从 Chromium 获取 chromedriver 的源代码,对其进行修改和编译。 I'm left with a list of dlls and the executable for this.我留下了一个 dll 列表和可执行文件。

Previously, I used NuGet to obtain the Selenium.Webdriver and Selenium.Webdriver.Chromedriver packages, but I was confused on how exactly chromedriver was running.以前,我使用 NuGet 来获取 Selenium.Webdriver 和 Selenium.Webdriver.Chromedriver 包,但我对 chromedriver 的运行方式感到困惑。 In the [solution_name]\packages\Selenium.WebDriver.ChromeDriver.77.0.3865.4000\driver\win32 folder, I saw that chromedriver.exe, and in the [solution_name]\packages\Selenium.WebDriver.ChromeDriver.77.0.3865.4000\build folder, I noticed a.targets file, which inside had a line which pointed to the.exe location.在 [solution_name]\packages\Selenium.WebDriver.ChromeDriver.77.0.3865.4000\driver\win32 文件夹中,我看到了 chromedriver.exe,在 [solution_name]\packages\Selenium.WebDriver.ChromeDriver.77.0.3865.4000\build文件夹,我注意到一个 .targets 文件,其中有一行指向 .exe 位置。 I thought it would be enough the replace the chromedriver.exe from NuGet w/ my custom built executable, and include the compiled dlls inside that folder as well.我认为将 NuGet 中的 chromedriver.exe 替换为我自定义构建的可执行文件就足够了,并将编译后的 dll 也包含在该文件夹中。 I ended up getting an error some dlls (such as base.dll, all files that I had included in that some directory) were missing.我最终得到一个错误,一些 dll(例如 base.dll,我包含在该目录中的所有文件)丢失了。

Any idea of how I can get this configuration to work, or again, if there's an easier way of going about this to modify the source code of chromedriver and use that w/ Selenium's webdriver?关于如何让这个配置工作的任何想法,或者再次,如果有更简单的方法来修改 chromedriver 的源代码并使用它 w/Selenium 的 webdriver?

Thank you!谢谢!

If you have built your custom chromedriver , then you can specify the modded driver's path before initializing the driver.如果您已经构建了自定义chromedriver ,那么您可以在初始化驱动程序之前指定修改后的驱动程序的路径。 This will force it to use the specified chromedriver instead of whichever one is in your $PATH这将强制它使用指定的chromedriver而不是$PATH中的任何一个

System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
WebDriver driver = new ChromeDriver();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM