Best Rod code snippet using rod.Navigate
query_test.go
Source:query_test.go
...12 "github.com/ysmood/gson"13)14func TestPageElements(t *testing.T) {15 g := setup(t)16 g.page.MustNavigate(g.srcFile("fixtures/input.html"))17 g.page.MustElement("input")18 list := g.page.MustElements("input")19 g.Eq("input", list.First().MustDescribe().LocalName)20 g.Eq("submit", list.Last().MustText())21}22func TestPagesQuery(t *testing.T) {23 g := setup(t)24 b := g.browser25 b.MustPage(g.srcFile("fixtures/click.html")).MustWaitLoad()26 pages := b.MustPages()27 g.True(pages.MustFind("button").MustHas("button"))28 g.Panic(func() { rod.Pages{}.MustFind("____") })29 g.True(pages.MustFindByURL("click.html").MustHas("button"))30 g.Panic(func() { rod.Pages{}.MustFindByURL("____") })31 _, err := pages.Find("____")32 g.Err(err)33 g.Eq(err.Error(), "cannot find page")34 g.Panic(func() {35 pages.MustFindByURL("____")36 })37 g.Panic(func() {38 g.mc.stubErr(1, proto.RuntimeCallFunctionOn{})39 pages.MustFind("button")40 })41 g.Panic(func() {42 g.mc.stubErr(1, proto.RuntimeCallFunctionOn{})43 pages.MustFindByURL("____")44 })45}46func TestPagesOthers(t *testing.T) {47 g := setup(t)48 list := rod.Pages{}49 g.Nil(list.First())50 g.Nil(list.Last())51 list = append(list, &rod.Page{})52 g.NotNil(list.First())53 g.NotNil(list.Last())54}55func TestPageHas(t *testing.T) {56 g := setup(t)57 g.page.MustNavigate(g.srcFile("fixtures/selector.html"))58 g.page.MustElement("body")59 g.True(g.page.MustHas("span"))60 g.False(g.page.MustHas("a"))61 g.True(g.page.MustHasX("//span"))62 g.False(g.page.MustHasX("//a"))63 g.True(g.page.MustHasR("button", "03"))64 g.False(g.page.MustHasR("button", "11"))65 g.mc.stubErr(1, proto.RuntimeCallFunctionOn{})66 g.Err(g.page.HasX("//a"))67 g.mc.stubErr(1, proto.RuntimeCallFunctionOn{})68 g.Err(g.page.HasR("button", "03"))69}70func TestElementHas(t *testing.T) {71 g := setup(t)72 g.page.MustNavigate(g.srcFile("fixtures/selector.html"))73 b := g.page.MustElement("body")74 g.True(b.MustHas("span"))75 g.False(b.MustHas("a"))76 g.True(b.MustHasX("//span"))77 g.False(b.MustHasX("//a"))78 g.True(b.MustHasR("button", "03"))79 g.False(b.MustHasR("button", "11"))80}81func TestSearch(t *testing.T) {82 g := setup(t)83 p := g.page.MustNavigate(g.srcFile("fixtures/click.html"))84 el := p.MustSearch("click me")85 g.Eq("click me", el.MustText())86 g.True(el.MustClick().MustMatches("[a=ok]"))87 _, err := p.Sleeper(rod.NotFoundSleeper).Search("not-exists")88 g.True(errors.Is(err, &rod.ErrElementNotFound{}))89 g.Eq(err.Error(), "cannot find element")90 // when search result is not ready91 {92 g.mc.stub(1, proto.DOMGetSearchResults{}, func(send StubSend) (gson.JSON, error) {93 return gson.New(nil), cdp.ErrCtxNotFound94 })95 p.MustSearch("click me")96 }97 // when node id is zero98 {99 g.mc.stub(1, proto.DOMGetSearchResults{}, func(send StubSend) (gson.JSON, error) {100 return gson.New(proto.DOMGetSearchResultsResult{101 NodeIds: []proto.DOMNodeID{0},102 }), nil103 })104 p.MustSearch("click me")105 }106 g.Panic(func() {107 g.mc.stubErr(1, proto.DOMPerformSearch{})108 p.MustSearch("click me")109 })110 g.Panic(func() {111 g.mc.stubErr(1, proto.DOMGetSearchResults{})112 p.MustSearch("click me")113 })114 g.Panic(func() {115 g.mc.stubErr(1, proto.RuntimeCallFunctionOn{})116 p.MustSearch("click me")117 })118}119func TestSearchElements(t *testing.T) {120 g := setup(t)121 p := g.page.MustNavigate(g.srcFile("fixtures/selector.html"))122 {123 res, err := p.Search("button")124 g.E(err)125 c, err := res.All()126 g.E(err)127 g.Len(c, 4)128 g.mc.stubErr(1, proto.DOMGetSearchResults{})129 g.Err(res.All())130 g.mc.stubErr(1, proto.DOMResolveNode{})131 g.Err(res.All())132 }133 { // disable retry134 sleeper := func() utils.Sleeper { return utils.CountSleeper(1) }135 _, err := p.Sleeper(sleeper).Search("not-exists")136 g.Err(err)137 }138}139func TestSearchIframes(t *testing.T) {140 g := setup(t)141 p := g.page.MustNavigate(g.srcFile("fixtures/click-iframes.html"))142 el := p.MustSearch("button[onclick]")143 g.Eq("click me", el.MustText())144 g.True(el.MustClick().MustMatches("[a=ok]"))145}146func TestSearchIframesAfterReload(t *testing.T) {147 g := setup(t)148 p := g.page.MustNavigate(g.srcFile("fixtures/click-iframes.html"))149 frame := p.MustElement("iframe").MustFrame().MustElement("iframe").MustFrame()150 frame.MustReload()151 el := p.MustSearch("button[onclick]")152 g.Eq("click me", el.MustText())153 g.True(el.MustClick().MustMatches("[a=ok]"))154}155func TestPageRace(t *testing.T) {156 g := setup(t)157 p := g.page.MustNavigate(g.srcFile("fixtures/selector.html"))158 p.Race().Element("button").MustHandle(func(e *rod.Element) { g.Eq("01", e.MustText()) }).MustDo()159 g.Eq("01", p.Race().Element("button").MustDo().MustText())160 p.Race().ElementX("//button").MustHandle(func(e *rod.Element) { g.Eq("01", e.MustText()) }).MustDo()161 g.Eq("01", p.Race().ElementX("//button").MustDo().MustText())162 p.Race().ElementR("button", "02").MustHandle(func(e *rod.Element) { g.Eq("02", e.MustText()) }).MustDo()163 g.Eq("02", p.Race().ElementR("button", "02").MustDo().MustText())164 p.Race().MustElementByJS("() => document.querySelector('button')", nil).165 MustHandle(func(e *rod.Element) { g.Eq("01", e.MustText()) }).MustDo()166 g.Eq("01", p.Race().MustElementByJS("() => document.querySelector('button')", nil).MustDo().MustText())167 raceFunc := func(p *rod.Page) (*rod.Element, error) {168 el := p.MustElement("button")169 g.Eq("01", el.MustText())170 return el, nil171 }172 p.Race().ElementFunc(raceFunc).MustHandle(func(e *rod.Element) { g.Eq("01", e.MustText()) }).MustDo()173 g.Eq("01", p.Race().ElementFunc(raceFunc).MustDo().MustText())174 el, err := p.Sleeper(func() utils.Sleeper { return utils.CountSleeper(2) }).Race().175 Element("not-exists").MustHandle(func(e *rod.Element) {}).176 ElementX("//not-exists").177 ElementR("not-exists", "test").MustHandle(func(e *rod.Element) {}).178 Do()179 g.Err(err)180 g.Nil(el)181 el, err = p.Race().MustElementByJS(`() => notExists()`, nil).Do()182 g.Err(err)183 g.Nil(el)184}185func TestPageRaceRetryInHandle(t *testing.T) {186 g := setup(t)187 p := g.page.MustNavigate(g.srcFile("fixtures/selector.html"))188 p.Race().Element("div").MustHandle(func(e *rod.Element) {189 go func() {190 utils.Sleep(0.5)191 e.MustElement("button").MustEval(`() => this.innerText = '04'`)192 }()193 e.MustElement("button").MustWait("() => this.innerText === '04'")194 }).MustDo()195}196func TestPageElementX(t *testing.T) {197 g := setup(t)198 g.page.MustNavigate(g.srcFile("fixtures/selector.html"))199 g.page.MustElement("body")200 txt := g.page.MustElementX("//div").MustElementX("./button").MustText()201 g.Eq(txt, "02")202}203func TestPageElementsX(t *testing.T) {204 g := setup(t)205 g.page.MustNavigate(g.srcFile("fixtures/selector.html"))206 g.page.MustElement("body")207 list := g.page.MustElementsX("//button")208 g.Len(list, 4)209}210func TestElementR(t *testing.T) {211 g := setup(t)212 p := g.page.MustNavigate(g.srcFile("fixtures/selector.html"))213 el := p.MustElementR("button", `\d1`)214 g.Eq("01", el.MustText())215 el = p.MustElement("div").MustElementR("button", `03`)216 g.Eq("03", el.MustText())217 p = g.page.MustNavigate(g.srcFile("fixtures/input.html"))218 el = p.MustElementR("input", `submit`)219 g.Eq("submit", el.MustText())220 el = p.MustElementR("input", `placeholder`)221 g.Eq("blur", *el.MustAttribute("id"))222 el = p.MustElementR("option", `/cc/i`)223 g.Eq("CC", el.MustText())224}225func TestElementFromElement(t *testing.T) {226 g := setup(t)227 p := g.page.MustNavigate(g.srcFile("fixtures/selector.html"))228 el := p.MustElement("div").MustElement("button")229 g.Eq("02", el.MustText())230}231func TestElementsFromElement(t *testing.T) {232 g := setup(t)233 p := g.page.MustNavigate(g.srcFile("fixtures/input.html"))234 el := p.MustElement("form")235 list := p.MustElement("form").MustElements("option")236 g.Len(list, 4)237 g.Eq("B", list[1].MustText())238 g.mc.stubErr(1, proto.RuntimeCallFunctionOn{})239 g.Err(el.Elements("input"))240}241func TestElementParent(t *testing.T) {242 g := setup(t)243 p := g.page.MustNavigate(g.srcFile("fixtures/input.html"))244 el := p.MustElement("input").MustParent()245 g.Eq("FORM", el.MustEval(`() => this.tagName`).String())246}247func TestElementParents(t *testing.T) {248 g := setup(t)249 p := g.page.MustNavigate(g.srcFile("fixtures/input.html"))250 g.Len(p.MustElement("option").MustParents("*"), 4)251 g.Len(p.MustElement("option").MustParents("form"), 1)252}253func TestElementSiblings(t *testing.T) {254 g := setup(t)255 p := g.page.MustNavigate(g.srcFile("fixtures/selector.html"))256 el := p.MustElement("div")257 a := el.MustPrevious()258 b := el.MustNext()259 g.Eq(a.MustText(), "01")260 g.Eq(b.MustText(), "04")261}262func TestElementFromElementX(t *testing.T) {263 g := setup(t)264 p := g.page.MustNavigate(g.srcFile("fixtures/selector.html"))265 el := p.MustElement("div").MustElementX("./button")266 g.Eq("02", el.MustText())267}268func TestElementsFromElementsX(t *testing.T) {269 g := setup(t)270 p := g.page.MustNavigate(g.srcFile("fixtures/selector.html"))271 list := p.MustElement("div").MustElementsX("./button")272 g.Len(list, 2)273}274func TestElementTracing(t *testing.T) {275 g := setup(t)276 g.browser.Trace(true)277 g.browser.Logger(utils.LoggerQuiet)278 defer func() {279 g.browser.Trace(defaults.Trace)280 g.browser.Logger(rod.DefaultLogger)281 }()282 p := g.page.MustNavigate(g.srcFile("fixtures/click.html"))283 g.Eq(`rod.element("code") html`, p.MustElement("html").MustElement("code").MustText())284}285func TestPageElementByJS(t *testing.T) {286 g := setup(t)287 p := g.page.MustNavigate(g.srcFile("fixtures/click.html"))288 g.Eq(p.MustElementByJS(`() => document.querySelector('button')`).MustText(), "click me")289 _, err := p.ElementByJS(rod.Eval(`() => 1`))290 g.Is(err, &rod.ErrExpectElement{})291 g.Eq(err.Error(), "expect js to return an element, but got: {\"type\":\"number\",\"value\":1,\"description\":\"1\"}")292}293func TestPageElementsByJS(t *testing.T) {294 g := setup(t)295 p := g.page.MustNavigate(g.srcFile("fixtures/selector.html")).MustWaitLoad()296 g.Len(p.MustElementsByJS("() => document.querySelectorAll('button')"), 4)297 _, err := p.ElementsByJS(rod.Eval(`() => [1]`))298 g.Is(err, &rod.ErrExpectElements{})299 g.Eq(err.Error(), "expect js to return an array of elements, but got: {\"type\":\"number\",\"value\":1,\"description\":\"1\"}")300 _, err = p.ElementsByJS(rod.Eval(`() => 1`))301 g.Eq(err.Error(), "expect js to return an array of elements, but got: {\"type\":\"number\",\"value\":1,\"description\":\"1\"}")302 _, err = p.ElementsByJS(rod.Eval(`() => foo()`))303 g.Err(err)304 g.mc.stubErr(1, proto.RuntimeGetProperties{})305 _, err = p.ElementsByJS(rod.Eval(`() => [document.body]`))306 g.Err(err)307 g.mc.stubErr(4, proto.RuntimeCallFunctionOn{})308 g.Err(p.Elements("button"))309}310func TestPageElementTimeout(t *testing.T) {311 g := setup(t)312 page := g.page.MustNavigate(g.blank())313 start := time.Now()314 _, err := page.Timeout(300 * time.Millisecond).Element("not-exists")315 g.Is(err, context.DeadlineExceeded)316 g.Gte(time.Since(start), 300*time.Millisecond)317}318func TestPageElementMaxRetry(t *testing.T) {319 g := setup(t)320 page := g.page.MustNavigate(g.blank())321 s := func() utils.Sleeper { return utils.CountSleeper(5) }322 _, err := page.Sleeper(s).Element("not-exists")323 g.Is(err, &utils.ErrMaxSleepCount{})324}325func TestElementsOthers(t *testing.T) {326 g := setup(t)327 list := rod.Elements{}328 g.Nil(list.First())329 g.Nil(list.Last())330}...
page_eval_test.go
Source:page_eval_test.go
...12 g := setup(t)13 p := g.newPage()14 p.MustEvalOnNewDocument(`window.rod = 'ok'`)15 // to activate the script16 p.MustNavigate(g.blank())17 g.Eq(p.MustEval("() => rod").String(), "ok")18 g.Panic(func() {19 g.mc.stubErr(1, proto.PageAddScriptToEvaluateOnNewDocument{})20 p.MustEvalOnNewDocument(`1`)21 })22}23func TestPageEval(t *testing.T) {24 g := setup(t)25 page := g.page.MustNavigate(g.blank())26 g.Eq(3, page.MustEval(`27 (a, b) => a + b28 `, 1, 2).Int())29 g.Eq(10, page.MustEval(`(a, b, c, d) => a + b + c + d`, 1, 2, 3, 4).Int())30 g.Eq(page.MustEval(`function() {31 return 1132 }`).Int(), 11)33 g.Eq(page.MustEval(` ; () => 1; `).Int(), 1)34 // reuse obj35 obj := page.MustEvaluate(rod.Eval(`() => () => 'ok'`).ByObject())36 g.Eq("ok", page.MustEval(`f => f()`, obj).Str())37 _, err := page.Eval(`10`)38 g.Has(err.Error(), `eval js error: TypeError: 10.apply is not a function`)39 _, err = page.Eval(`() => notExist()`)40 g.Is(err, &rod.ErrEval{})41 g.Has(err.Error(), `eval js error: ReferenceError: notExist is not defined`)42}43func TestPageEvaluateRetry(t *testing.T) {44 g := setup(t)45 page := g.page.MustNavigate(g.blank())46 g.mc.stub(1, proto.RuntimeCallFunctionOn{}, func(send StubSend) (gson.JSON, error) {47 g.mc.stub(1, proto.RuntimeCallFunctionOn{}, func(send StubSend) (gson.JSON, error) {48 return gson.New(nil), cdp.ErrCtxNotFound49 })50 return gson.New(nil), cdp.ErrCtxNotFound51 })52 g.Eq(1, page.MustEval(`() => 1`).Int())53}54func TestPageUpdateJSCtxIDErr(t *testing.T) {55 g := setup(t)56 page := g.page.MustNavigate(g.srcFile("./fixtures/click-iframe.html"))57 g.mc.stub(1, proto.RuntimeCallFunctionOn{}, func(send StubSend) (gson.JSON, error) {58 g.mc.stubErr(1, proto.RuntimeEvaluate{})59 return gson.New(nil), cdp.ErrCtxNotFound60 })61 g.Err(page.Eval(`() => 1`))62 frame := page.MustElement("iframe").MustFrame()63 frame.MustReload()64 g.mc.stubErr(1, proto.DOMDescribeNode{})65 g.Err(frame.Element(`button`))66 frame.MustReload()67 g.mc.stubErr(1, proto.DOMResolveNode{})68 g.Err(frame.Element(`button`))69}70func TestPageExpose(t *testing.T) {71 g := setup(t)72 page := g.newPage(g.blank()).MustWaitLoad()73 stop := page.MustExpose("exposedFunc", func(g gson.JSON) (interface{}, error) {74 return g.Get("k").Str(), nil75 })76 utils.All(func() {77 res := page.MustEval(`() => exposedFunc({k: 'a'})`)78 g.Eq("a", res.Str())79 }, func() {80 res := page.MustEval(`() => exposedFunc({k: 'b'})`)81 g.Eq("b", res.Str())82 })()83 // survive the reload84 page.MustReload().MustWaitLoad()85 res := page.MustEval(`() => exposedFunc({k: 'ok'})`)86 g.Eq("ok", res.Str())87 stop()88 g.Panic(func() {89 stop()90 })91 g.Panic(func() {92 page.MustReload().MustWaitLoad().MustEval(`() => exposedFunc()`)93 })94 g.Panic(func() {95 g.mc.stubErr(1, proto.RuntimeCallFunctionOn{})96 page.MustExpose("exposedFunc", nil)97 })98 g.Panic(func() {99 g.mc.stubErr(1, proto.RuntimeAddBinding{})100 page.MustExpose("exposedFunc2", nil)101 })102 g.Panic(func() {103 g.mc.stubErr(1, proto.PageAddScriptToEvaluateOnNewDocument{})104 page.MustExpose("exposedFunc", nil)105 })106}107func TestObjectRelease(t *testing.T) {108 g := setup(t)109 res, err := g.page.Evaluate(rod.Eval(`() => document`).ByObject())110 g.E(err)111 g.page.MustRelease(res)112}113func TestPromiseLeak(t *testing.T) {114 g := setup(t)115 /*116 Perform a slow action then navigate the page to another url,117 we can see the slow operation will still be executed.118 */119 p := g.page.MustNavigate(g.blank())120 utils.All(func() {121 _, err := p.Eval(`() => new Promise(r => setTimeout(() => r(location.href), 1000))`)122 g.Is(err, cdp.ErrCtxDestroyed)123 }, func() {124 utils.Sleep(0.3)125 p.MustNavigate(g.blank())126 })()127}128func TestObjectLeak(t *testing.T) {129 g := setup(t)130 /*131 Seems like it won't leak132 */133 p := g.page.MustNavigate(g.blank())134 obj := p.MustEvaluate(rod.Eval("() => ({a:1})").ByObject())135 p.MustReload().MustWaitLoad()136 g.Panic(func() {137 p.MustEvaluate(rod.Eval(`obj => obj`, obj))138 })139}140func TestPageObjectErr(t *testing.T) {141 g := setup(t)142 g.Panic(func() {143 g.page.MustObjectToJSON(&proto.RuntimeRemoteObject{144 ObjectID: "not-exists",145 })146 })147 g.Panic(func() {148 g.page.MustElementFromNode(&proto.DOMNode{NodeID: -1})149 })150 g.Panic(func() {151 node := g.page.MustNavigate(g.blank()).MustElement(`body`).MustDescribe()152 g.mc.stubErr(1, proto.DOMResolveNode{})153 g.page.MustElementFromNode(node)154 })155}156func TestGetJSHelperRetry(t *testing.T) {157 g := setup(t)158 g.page.MustNavigate(g.srcFile("fixtures/click.html"))159 g.mc.stub(1, proto.RuntimeCallFunctionOn{}, func(send StubSend) (gson.JSON, error) {160 return gson.JSON{}, cdp.ErrCtxNotFound161 })162 g.page.MustElements("button")163}164func TestConcurrentEval(t *testing.T) {165 g := setup(t)166 p := g.page.MustNavigate(g.blank())167 list := make(chan int, 2)168 start := time.Now()169 utils.All(func() {170 list <- p.MustEval(`() => new Promise(r => setTimeout(r, 2000, 2))`).Int()171 }, func() {172 list <- p.MustEval(`() => new Promise(r => setTimeout(r, 1000, 1))`).Int()173 })()174 duration := time.Since(start)175 g.Gt(duration, 1000*time.Millisecond)176 g.Lt(duration, 3000*time.Millisecond)177 g.Eq([]int{<-list, <-list}, []int{1, 2})178}179func TestPageSlowRender(t *testing.T) {180 g := setup(t)181 p := g.page.MustNavigate(g.srcFile("./fixtures/slow-render.html"))182 g.Eq(p.MustElement("div").MustText(), "ok")183}184func TestPageIframeReload(t *testing.T) {185 g := setup(t)186 p := g.page.MustNavigate(g.srcFile("./fixtures/click-iframe.html"))187 frame := p.MustElement("iframe").MustFrame()188 btn := frame.MustElement("button")189 g.Eq(btn.MustText(), "click me")190 frame.MustReload()191 btn = frame.MustElement("button")192 g.Eq(btn.MustText(), "click me")193 g.Has(*p.MustElement("iframe").MustAttribute("src"), "click.html")194}195func TestPageObjCrossNavigation(t *testing.T) {196 g := setup(t)197 p := g.page.MustNavigate(g.blank())198 obj := p.MustEvaluate(rod.Eval(`() => ({})`).ByObject())199 g.page.MustNavigate(g.blank())200 _, err := p.Evaluate(rod.Eval(`() => 1`).This(obj))201 g.Is(err, &rod.ErrObjectNotFound{})202 g.Has(err.Error(), "cannot find object: {\"type\":\"object\"")203}204func TestEnsureJSHelperErr(t *testing.T) {205 g := setup(t)206 p := g.page.MustNavigate(g.blank())207 g.mc.stubErr(2, proto.RuntimeCallFunctionOn{})208 g.Err(p.Elements(`button`))209}210func TestEvalOptionsString(t *testing.T) {211 g := setup(t)212 p := g.page.MustNavigate(g.srcFile("fixtures/click.html"))213 el := p.MustElement("button")214 g.Eq(rod.Eval(`() => this.parentElement`).This(el.Object).String(), "() => this.parentElement() button")215}...
Navigate
Using AI Code Generation
1import (2func main() {3 browser := rod.New().Connect()4 page := browser.Page("")5 fmt.Println("Page Title is : ", page.MustTitle())6 fmt.Println("Page URL is : ", page.MustInfo().URL)7 fmt.Println("Page Cookies are : ", page.MustCookies())8 fmt.Println("Page Cookies are : ", page.MustEval("document.title"))9 fmt.Println("Page Cookies are : ", page.MustElement("body").MustHTML())10 fmt.Println("Page Cookies are : ", page.MustElement("body").MustText())11 fmt.Println("Page Cookies are : ", page.MustElement("body").MustDescription())12 fmt.Println("Page Cookies are : ", page.MustElement("body").MustScreenshot())13 fmt.Println("Page Cookies are : ", page.MustElement("body").MustVisible())14 fmt.Println("Page Cookies are : ", page.MustElement("body").MustInteractable())15 fmt.Println("Page Cookies are : ", page.MustElement("body").MustNode())16 fmt.Println("Page Cookies are : ", page.MustElement("body").MustBox())17 fmt.Println("Page Cookies are : ", page.MustElement("body").MustStale())18 fmt.Println("Page Cookies are : ", page.MustElement("body").MustHandle())19 fmt.Println("Page Cookies are : ", page.MustElement("body").MustVisibleCenter())20 fmt.Println("Page Cookies are : ", page.MustElement("body").MustInteractableCenter())21 fmt.Println("Page Cookies are : ", page.MustElement("body").MustVisiblePoint())22 fmt.Println("Page Cookies are : ", page.MustElement("body").MustInteractablePoint())23 fmt.Println("Page Cookies are : ", page.MustElement("body").MustNodes())24 fmt.Println("Page Cookies are : ", page.MustElement("body").MustNodes(proto.DOMQuerySelectorAll{25 }))26 fmt.Println("Page Cookies are : ", page.MustElement("body").MustNodesR(proto.DOMQuerySelectorAll{27 }, 2))28 fmt.Println("Page Cookies are : ", page.MustElement("body").MustNodesE(proto.DOMQuerySelectorAll{29 }, 2))30 fmt.Println("Page Cookies are : ", page.MustElement("body").MustNodesF(proto.DOMQuerySelectorAll{
Navigate
Using AI Code Generation
1import (2func main() {3 browser := rod.New().MustConnect()4 fmt.Println(page.MustInfo().URL)5}6import (7func main() {8 browser := rod.New().MustConnect()9 fmt.Println(page.MustInfo().URL)10}11import (12func main() {13 browser := rod.New().MustConnect()14 fmt.Println(page.MustInfo().URL)15}16import (17func main() {18 browser := rod.New().MustConnect()19 fmt.Println(page.MustInfo().URL)20}21import (22func main() {23 browser := rod.New().MustConnect()24 fmt.Println(page.MustInfo().URL)25}26import (27func main() {28 browser := rod.New().MustConnect()29 fmt.Println(page.MustInfo().URL)30}31import (32func main() {33 browser := rod.New().MustConnect
Navigate
Using AI Code Generation
1import (2func main() {3 browser := rod.New().ControlURL(launcher.New().MustLaunch()).MustConnect()4 page := browser.MustPage("")5}6import (7func main() {8 browser := rod.New().ControlURL(launcher.New().MustLaunch()).MustConnect()9 page := browser.MustPage("")10 elements := page.MustElements("#gb > div > div > div.gb_Fc.gb_Hc.gb_R > div > ul > li:nth-child(1) > a")11 fmt.Println(elements)12}13import (14func main() {15 browser := rod.New().ControlURL(launcher.New().MustLaunch()).MustConnect()16 page := browser.MustPage("")17 elements := page.MustElementsX("/html/body/div[1]/div[2]/div[2]/div[2]/div[2]/div[2]/div[1]/div[2]/div[2]/div/div[1]/div[1]/div/div[1]/div/div[1]/a")18 fmt.Println(elements)19}20import (
Navigate
Using AI Code Generation
1import (2func main() {3 browser := rod.New().ControlURL(launcher.New().Headless(false).Launch()).MustConnect()4 title := page.MustTitle()5 fmt.Println(title)6}7import (8func main() {9 browser := rod.New().ControlURL(launcher.New().Headless(false).Launch()).MustConnect()10 title := page.MustTitle()11 fmt.Println(title)12 text := page.MustElement("body").MustText()13 fmt.Println(text)14}15import (16func main() {17 browser := rod.New().ControlURL(launcher.New().Headless(false).Launch()).MustConnect()18 title := page.MustTitle()19 fmt.Println(title)20 text := page.MustElement("body").MustText()21 fmt.Println(text)22 element := page.MustElement("body")23 fmt.Println(element)24}25Element: <body jsname="t3bXGc" class="VfPpkd-RLmnJb" jscontroller="jK7moc" jsaction="rcuQ6b:npT2md;keydown:npT2md;input:npT2
Navigate
Using AI Code Generation
1import (2func main() {3 browser := rod.New().Connect()4 fmt.Println(page.Element("title").Text())5 browser.Close()6}7import (8func main() {9 browser := rod.New().Connect()10 fmt.Println(page.Element("title").Text())11 browser.Close()12}13import (14func main() {15 browser := rod.New().Connect()16 browser.Close()17}18import (19func main() {20 browser := rod.New().Connect()21 fmt.Println(page.Elements("title").Text())22 browser.Close()23}24import (25func main() {26 browser := rod.New().Connect()27 browser.Close()28}
Navigate
Using AI Code Generation
1import (2func main() {3 browser := rod.New().ControlURL(launcher.New().MustLaunch()).MustConnect()4 fmt.Println(page.MustTitle())5 fmt.Println(page.MustHTML())6 fmt.Println(page.MustURL())7 fmt.Println(page.MustCookies())8 fmt.Println(page.MustElements("input"))9 fmt.Println(page.MustElement("input"))10 fmt.Println(page.MustElementR("input", "type", "submit"))11 fmt.Println(page.MustElementX("/html/body/div[1]/div[3]/form/div[2]/div[1]/div[1]/div/div[2]/input"))12 fmt.Println(page.MustElementByJS(`document.querySelector("input")`))13 fmt.Println(page.MustElementByJS(`document.querySelector("input")`, "type", "submit"))14 fmt.Println(page.MustElementByJS(`document.querySelector("input")`, rod.NewEvalOptions().WithThis("this").WithArgs("Hello")))15 fmt.Println(page.MustElementR("input", "type", "submit").MustProperty("value"))16 fmt.Println(page.MustElementR("input", "type", "submit").MustAttribute("value"))17 fmt.Println(page.MustElementR("input", "type", "submit").MustHasClass("someClass"))18 fmt.Println(page.MustElementR("input", "type", "submit").MustText())19 fmt.Println(page.MustElementR("input", "type", "submit").MustVisible())20 fmt.Println(page.MustElementR("input", "type
Navigate
Using AI Code Generation
1import (2func main() {3 browser := rod.New().Connect()4 title := page.Title()5 fmt.Println(title)6}7import (8func main() {9 browser := rod.New().Connect()10 title := page.Title()11 fmt.Println(title)12 searchBox.Input("Selenium")13 searchButton.Click()14}15import (16func main() {17 browser := rod.New().Connect()18 title := page.Title()19 fmt.Println(title)20 searchBox.Input("Selenium")
Navigate
Using AI Code Generation
1import "fmt"2func main() {3 fmt.Println("Total rods:", r1.totalRods)4 fmt.Println("Total length:", r1.totalLength)5 r1.Navigate()6 fmt.Println("Total rods:", r1.totalRods)7 fmt.Println("Total length:", r1.totalLength)8}
Navigate
Using AI Code Generation
1import (2func main() {3 browser := rod.New().ControlURL(launcher.New().Headless(false).Launch())4 page := browser.Page("")5}6import (7func main() {8 browser := rod.New().ControlURL(launcher.New().Headless(false).Launch())9 page := browser.Page("")10 page.WaitLoad()11}12import (13func main() {14 browser := rod.New().ControlURL(launcher.New().Headless(false).Launch())15 page := browser.Page("")16 page.WaitLoad()17 page.WaitRequestIdle()18}19import (20func main() {21 browser := rod.New().ControlURL(launcher.New().Headless(false).Launch())22 page := browser.Page("")23 page.WaitLoad()24 page.WaitRequestIdle()25 page.Element(`input[name="
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!