go-rod / rod

A Chrome DevTools Protocol driver for web automation and scraping.
https://go-rod.github.io
MIT License
5.43k stars 357 forks source link

Cannot click continue #1111

Open lyy077 opened 2 months ago

lyy077 commented 2 months ago

Rod Version: v0.116.2

The code to demonstrate your question

func Test() {
    u := launcher.New().HeadlessNew(false).MustLaunch()
    browser := rod.New().ControlURL(u).MustConnect()
    page := browser.MustPage("")

    defer browser.MustClose()

    var e proto.NetworkResponseReceived
    wait := page.WaitEvent(&e)
    page.MustNavigate("https://www.offers-pick.com/sports-outdoors/sleeping-bags")
    wait()

    originTab := page

    // 等待页面稳定
    page.MustWaitStable()
    elements, _ := page.ElementsX("//div[@class='product-list']//div[text() = ' CHECK PRICE ']")
    for _, element := range elements {
        element.MustClick()
        time.Sleep(time.Second * 1)
        browser.MustSetCookies()
        originTab.MustActivate()
        time.Sleep(time.Second * 2)
    }
    time.Sleep(time.Minute * 30)
}

go-rod Click on several elements. After clicking on an element, a new tab is opened. Switch back to the original tab and you can't click any further. The program is stuck.

ysmood commented 2 months ago

originTab is not the original tab, if you want to create 2 tabs, you should use Browser.MustPage or WaitOpen, etc.