1

我有一个使用SeleniumChrome的简单 F# 项目。我注意到当 Chrome 以无头模式启动时,chrome 对象没有定义。

另一方面,如果我“正常”运行它,则正确引用了 chrome 对象。

示例代码:

let chromeOptions = new ChromeOptions(BinaryLocation = _chrome)
chromeOptions.AddArguments
    (
        "--headless", 
        "--disable-gpu"                    
    )
let chrome = new ChromeDriver(chromeOptions, Url = "http://www.example.com")

try                
    Console.WriteLine(chrome.Capabilities.Platform)
    Console.WriteLine(chrome.Capabilities.BrowserName)
    Console.WriteLine(chrome.Capabilities.Version)
    let res = chrome.ExecuteScript("return chrome;")
    Console.WriteLine(res)
with e -> 
    Console.WriteLine(e.Message)

chrome.Quit()

如果我运行上面的代码,我会得到以下输出:

Starting ChromeDriver 2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8) on port 61158
Only local connections are allowed.
Any
chrome
62.0.3188.0
unknown error: chrome is not defined
  (Session info: headless chrome=62.0.3188.0)
  (Driver info: chromedriver=2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8),platform=Windows NT 10.0.15063 x86_64)

如果我省略无头选项,我会得到以下输出:

Starting ChromeDriver 2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8) on port 60248
Only local connections are allowed.
Any
chrome
62.0.3188.0
System.Collections.Generic.Dictionary`2[System.String,System.Object]

这是一个错误还是我错过了什么?

4

0 回答 0