package mainimport ("context""github.com/chromedp/chromedp""time"
)
var (URL = "https://account.wps.cn/"URL02 = "https://github.com/search"
)func main() {// chromdp依赖context上限传递参数ctx, _ := chromedp.NewExecAllocator(context.Background(),// 以默认配置的数组为基础,覆写headless参数// 当然也可以根据自己的需要进行修改,这个flag是浏览器的设置append(chromedp.DefaultExecAllocatorOptions[:],chromedp.Flag("headless", false),)...,)ctx, _= context.WithTimeout(ctx, 50*time.Second)ctx, _= chromedp.NewContext(ctx)chromedp.Run(ctx,chromedp.Tasks{// 导航到 https://github.com/searchchromedp.Navigate(URL02),chromedp.SendKeys(`input[name="q"]`,`chromedp`), // 等价于 chromedp.SendKeys(`//input[@name="q"]`, `chromedp`),chromedp.Submit(`input[name="q"]`), // 等价于 chromedp.Click(`#search_form > div > button`),  #search_form > div > button 通过 copy selector 获取})
}
效果如下