即使指定正确的路径,也要获取DriverServiceNotFoundException

时间:2019-06-27 16:38:07

标签: vb.net selenium-chromedriver

我有VB.net代码,该代码利用Selenium和Chrome驱动程序导航到页面并下载文件。无论是否指定无头选项,它都可以正常工作。但是我也想取消命令窗口。根据阅读的内容,我需要启动ChromeDriver,并为HideCommandPromptWindow属性指定“ true”。当我这样做时,会出现以下错误:

OpenQA.Selenium.DriverServiceNotFoundException   HResult = 0x80131500   消息=文件False \ chromedriver.exe不存在。可以从http://chromedriver.storage.googleapis.com/index.html下载驱动程序   来源= WebDriver   堆栈跟踪:    在OpenQA.Selenium.DriverService..ctor(字符串servicePath,Int32端口,字符串driverServiceExecutableName,Uri driverServiceDownloadUrl)    在OpenQA.Selenium.Chrome.ChromeDriverService..ctor(字符串可执行文件路径,字符串可执行文件名称,Int32端口)    在OpenQA.Selenium.Chrome.ChromeDriver..ctor(字符串chromeDriverDirectory,ChromeOptions选项)    在OpenQA.Selenium.Chrome.ChromeDriver..ctor(String chromeDriverDirectory)

我正在使用CommandWindow的TitleBar中显示的路径,它在运行和运行时会看到,因此我知道该路径和文件是有效的。

基于错误消息“文件False \ chromedrive.exe ...不存在...”的事实,看来我传递给该路径的arg某种程度上被评估为“假”。

这是正在运行的代码的片段-在第219或220行出错:

    Dim cOpt As New ChromeOptions()
    cOpt.AddArguments("--headless", "--no-sandbox", "--disable-gpu")

    Dim param As New Dictionary(Of String, Object)
    param.Add("behavior", "allow")
    param.Add("downloadPath", G.gRadiusExportsFolder)

    Dim cdp As String = FixPathSlash(My.Application.Info.DirectoryPath, False)

    Dim d As New ChromeDriver(cOpt)
    'LINE 219-- Dim d As New ChromeDriver(ChromeDriverService.CreateDefaultService(cdp, "chromedriver.exe").HideCommandPromptWindow = True)
    'LINE220-- Dim d As New ChromeDriver(ChromeDriverService.CreateDefaultService(cdp, "chromedriver.exe").HideCommandPromptWindow = True, cOpt)

    Wait(5)
    d.ExecuteChromeCommand("Page.setDownloadBehavior", param)

1 个答案:

答案 0 :(得分:0)

    Dim cOpt As New ChromeOptions()
    cOpt.AddArguments("--headless", "--no-sandbox", "--disable-gpu")

    Dim param As New Dictionary(Of String, Object)
    param.Add("behavior", "allow")
    param.Add("downloadPath", G.gRadiusExportsFolder)

    Dim driverService = ChromeDriverService.CreateDefaultService()
    driverService.HideCommandPromptWindow = True
    Dim d As New ChromeDriver(driverService, cOpt)

    Wait(5)
    d.ExecuteChromeCommand("Page.setDownloadBehavior", param)