0

I have my Chrome browser and I want to automate some actions using chromedriver. But when I use my default profile (default user or new "bot" profile) I always start with cleared cookies for that profile.

Can I automate existing Chrome user activity with chromedriver?

Here is code example:

package chrome

import (
    "fmt"
    "github.com/sclevine/agouti"
    "time"
)

func getDriver() (driver *agouti.WebDriver, stop func(), err error) {
    chromeOptions := []string{
        "--user-data-dir=/Users/robbo/Library/Application Support/Google/Chrome",
        "--profile-directory=Profile 1",
    }

    driver = agouti.ChromeDriver(agouti.ChromeOptions("args", chromeOptions))
    if err = driver.Start(); err != nil {
        return
    }

    stop = func() {
        _ = driver.Stop()
    }
    return
}

func NavigateToPageWithSession(project string) (err error) {
    driver, stop, err := getDriver()
    if err != nil {
        return
    }
    defer stop()

    page, err := driver.NewPage()
    if err != nil {
        return
    }

    url := fmt.Sprintf("https://stackoverflow.com/")
    err = page.Navigate(url)
    return
}
zored
  • 2,718
  • 3
  • 19
  • 23
  • 1
    See this: https://stackoverflow.com/questions/14480717/load-chrome-profile-using-selenium-webdriver-using-java Making a copy of the directory is best... – pcalkins Nov 06 '19 at 20:58
  • Thanks! Does that preserve cookies? Maybe my Golang implementation causes this behaviour... – zored Nov 08 '19 at 08:40
  • 1
    the behavior of starting with a fresh profile each time is the default for the webdriver. This is a clean state and is the most important test case. – pcalkins Nov 08 '19 at 18:35
  • and yes, the cookies are stored in the profile folder. (and also in app data per machine user...) – pcalkins Nov 08 '19 at 22:04

0 Answers0