Skip to content

Instantly share code, notes, and snippets.

@jacoduplessis
Created November 14, 2018 05:53
Show Gist options
  • Save jacoduplessis/322d695d4cdab6ce866b939964588642 to your computer and use it in GitHub Desktop.
Save jacoduplessis/322d695d4cdab6ce866b939964588642 to your computer and use it in GitHub Desktop.
Running headless firefox without selenium in golang.
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