I'm trying to log into Youtube, which redirects to accounts.google.com/ServiceLogin?service=youtube... with chromedp. For some reason it times out trying to retrieve anything from that page. Most of the selectors have randomly generated classes but that shouldn't prevent fetching body, which is does. Screenshot shows the login page so it's navigating there correctly but it can't find anything on the page. There are iframes but the login form/input isn't in one, and the #identifierId
can't be found.
Here is a code snippet:
func main() {
// create chrome instance
var buf []byte
ctx, cancel := chromedp.NewContext(
context.Background(),
// chromedp.WithDebugf(log.Printf),
)
defer cancel()
// create a timeout
ctx, cancel = context.WithTimeout(ctx, 15*time.Second)
defer cancel()
// navigate to a page, wait for an element, click
var u string
err := chromedp.Run(ctx,
chromedp.Navigate(`https://youtube.com`),
chromedp.Click(`#buttons > ytd-button-renderer > a`),
chromedp.SendKeys(`#identifierId`, "bobboshmo@gmail.com", chromedp.ByID),
chromedp.Location(&u),
)
if err != nil {
log.Fatal(err)
}
log.Printf(u)
// capture entire browser viewport, returning png with quality=90
if err := chromedp.Run(ctx, fullScreenshot(u, 90, &buf)); err != nil {
log.Fatal(err)
}
if err := ioutil.WriteFile("fullScreenshot.png", buf, 0o644); err != nil {
log.Fatal(err)
}
}
func fullScreenshot(urlstr string, quality int, res *[]byte) chromedp.Tasks {
return chromedp.Tasks{
chromedp.Navigate(urlstr),
chromedp.FullScreenshot(res, quality),
}
}