go-rod / rod

A Chrome DevTools Protocol driver for web automation and scraping.

Home Page:https://go-rod.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is there any way to wait for a certain element in the page:

cplasfwst opened this issue · comments

Rod Version: vv0.114.7

Is there any way to wait for a certain element in the page:
page2.MustElementX(//div[@data-e2e="comment-list"]).MustElementsX(./div)
The following div is completely loaded before continuing to perform subsequent operations?
Because sometimes the number of loads may be 0 or 1, the morethan method should not be used appropriately.

Please add a valid Rod Version: v0.0.0 to your issue. Current version is v0.114.8

generated by check-issue

例如我的代码
//寻找评论按钮 page2.MustElementX(//div[@data-e2e="feed-comment-icon"]).MustClick() //.MustWaitLoad() //page2.MustWaitStable() //wait() //time.Sleep(time.Second * 3) //-----------先获取评论框,等待评论框出现后再获取评论条 //page2.MustElementX(//div[@Class="Gacm1K1M comment-header-inner-container"]) //fmt.Println("等待完成") //time.Sleep(time.Second * 5) //page2.MustElementX(//div[@data-e2e="comment-list"]`).MustWaitLoad()
//寻找评论列表里面的所有评论

	p2 := page2.MustElementX(`//div[@data-e2e="comment-list"]`).MustElementsX(`./div`)
	fmt.Println("一共加载了评论:", len(p2))`

Only delayed waiting will cause all 21 divs to appear, but I am not sure how long time.sleep will last.
If you use the method I commented out above, only one child element will appear. This is the cmd output:
Total comments loaded: 1
If you use time.sleep (2 seconds), you can fully load 21

commented

I got lucky with err = page.WaitElementsMoreThan("selector", 0).

I got lucky with err = page.WaitElementsMoreThan("selector", 0).

I seem to have solved the above problem. Can I operate 2 pages at the same time?

Can I operate 2 pages at the same time?

Yes