profile_dir = File.expand_path("profile",__dir__).encode("UTF-8")
U_d_Dir = "--user-data-dir=" + profile_dir
options = Selenium::WebDriver::Chrome::Options.new(args: ["--headless" ,'--no-sandbox', U_d_Dir])
driver = Selenium::WebDriver.for :chrome, options: options
reference [Unresolved] Chrome headless mode cannot be used with Selenium Web Driver for which user-data-dir is set. https://teratail.com/questions/142395 Error occurs when headless and user-data-dir options are specified at the same time in chromedriver https://ja.stackoverflow.com/questions/51441/chromedriver-%E3%81%A7-headless-%E3%81%A8-user-data-dir-%E3%81%AE%E3%82%AA%E3%83%97%E3%82%B7%E3%83%A7%E3%83%B3%E3%82%92%E5%90%8C%E6%99%82%E3%81%AB%E6%8C%87%E5%AE%9A%E3%81%99%E3%82%8B%E3%81%A8%E3%82%A8%E3%83%A9%E3%83%BC%E3%81%8C%E7%99%BA%E7%94%9F%E3%81%99%E3%82%8B
Recommended Posts