go – Cannot get current window title-ThrowExceptions

Exception or error:

I try to get windows title on gmail inbox page after it was opened.
For some reason the title is empty.
What am I doing wrong?
Chromedp is used for browser automation.

...
var title string

err := chromedp.Run(taskCtx,
    chromedp.Navigate(`https://mail.google.com/mail/u/0/h/`),
    ...
    chromedp.WaitVisible(`body`), // gmail inbox page was opened in browser
    chromedp.Title(&title),
)
if err != nil {
    if err.Error() == "context deadline exceeded" {
        log.Println(err) // this line executed
    } else {
        log.Fatal(err)
    }
}

log.Printf("success.\ntitle: %s\n", title) // title is empty!

The output in console:

2019/10/22 08:01:49 context deadline exceeded

2019/10/22 08:01:49 success.

title:

How to solve:

The Title function is probably not executed due to the error printed in the output. You should fix this before focusing on the title

Leave a Reply

Your email address will not be published. Required fields are marked *