Created
November 14, 2018 05:53
-
-
Save jacoduplessis/322d695d4cdab6ce866b939964588642 to your computer and use it in GitHub Desktop.
Running headless firefox without selenium in golang.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/tebeka/selenium" | |
"github.com/tebeka/selenium/firefox" | |
"log" | |
"os" | |
) | |
func main() { | |
selenium.SetDebug(true) | |
port := 4444 | |
service, err := selenium.NewGeckoDriverService("/usr/local/bin/geckodriver", port, selenium.Output(os.Stderr)) | |
if err != nil { | |
log.Fatal(err) | |
} | |
defer service.Stop() | |
caps := selenium.Capabilities{} | |
caps.AddFirefox(firefox.Capabilities{ | |
Binary: "/home/jaco/Apps/firefox-dev/firefox", | |
Args: []string{"--headless"}, | |
}) | |
wd, err := selenium.NewRemote(caps, fmt.Sprintf("http://localhost:%d", port)) | |
if err != nil { | |
log.Fatal(err) | |
} | |
defer wd.Quit() | |
wd.Get("http://localhost") | |
title, _ := wd.Title() | |
fmt.Print(title) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment