Closed chekun closed 6 months ago
Rod Version: v0.114.5
Clone Rod to your local and cd to the repository:
git clone https://github.com/go-rod/rod cd rod git checkout v0.114.5
Use your code to replace the content of function TestRod in file rod_test.go.
TestRod
rod_test.go
Test your code with: go test -run TestRod, make sure it fails as expected.
go test -run TestRod
Replace ALL THE CONTENT under "The code to demonstrate your question" with your TestRod function, like below:
func TestRod(t *testing.T) { l := launcher.New() l = l.Headless(false).Bin("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome") controlURL, _ := l.Launch() browser := rod.New().Trace(true).ControlURL(controlURL).MustConnect() defer browser.Close() page := browser.MustPage("https://www.baidu.com").MustWaitLoad() blockedEl, err := page.Timeout(2*time.Second).ElementR("div", "You’re Temporarily Blocked") log.Println(blockedEl, err) log.Println("text is") log.Println(blockedEl.Text()) log.Println("html is") log.Println(blockedEl.HTML()) }
2023/11/29 18:04:09 <div#006a894f3906632b> <nil> 2023/11/29 18:04:09 text is 2023/11/29 18:04:09 rod.elementR("div","/You’re Temporarily Blocked/") <nil> 2023/11/29 18:04:09 html is 2023/11/29 18:04:09 <div id="006a894f3906632b" style="position: fixed; z-index: 2147483647; border: none; border-radius: 3px; box-shadow: rgb(95, 50, 50) 0px 0px 3px; pointer-events: none; box-sizing: border-box; left: 0px; top: 0px; height: 0px; width: 500px;"><div style="position: absolute; color: rgb(204, 38, 214); font-size: 12px; background: rgba(255, 255, 255, 0.92); box-shadow: rgb(51, 51, 51) 0px 0px 3px; padding: 2px 5px; border-radius: 3px; white-space: nowrap; top: 0px;"><code>rod.elementR("div","/You’re Temporarily Blocked/") </code></div></div> <nil>
I expect to see blockedEl == nil
blockedEl == nil
I have no idea to solve this, I mean if the element is not there ,shouldn't it be nil ?
Seeing the same issue here
Rod Version: v0.114.5
The code to demonstrate your question
Clone Rod to your local and cd to the repository:
Use your code to replace the content of function
TestRod
in filerod_test.go
.Test your code with:
go test -run TestRod
, make sure it fails as expected.Replace ALL THE CONTENT under "The code to demonstrate your question" with your
TestRod
function, like below:What you got
What you expected to see
I expect to see
blockedEl == nil
What have you tried to solve the question
I have no idea to solve this, I mean if the element is not there ,shouldn't it be nil ?