How to use MustInfo method of rod Package

Best Rod code snippet using rod.MustInfo

main.go

Source:main.go Github

copy

Full Screen

...94 return chromeVersion.WebSocketDebuggerUrl95}96func checkLimit (page *rod.Page) {97 time.Sleep(time.Millisecond*1000)98 logger.Debug(page.MustInfo().URL)99 page.MustScreenshotFullPage("screenshot/CL01.png")100 logger.Debug("%d", len(page.MustElementsX(`//td[contains(@data-date, "2022-07") and class=".bg-color-blueLight"]`)))101 // for element := range elements {102 // logger.Debug("%s", element)103 // // MustElement(`div[class="fc-event fc-event-hori fc-event-start fc-event-end bg-color-blueLight"]`).a)104 // }105 os.Exit(1)106}107func initRod() (*rod.Browser) {108 browser := rod.New().MustConnect()109 // url := GetWebSocketDebuggerUrl()110 // browser := rod.New().ControlURL(url).MustConnect()111 browser.DefaultDevice(devices.IPadMini)112 return browser113}114func login (browser *rod.Browser) (*rod.Page) {115 page := browser.MustPage("https://assist9.i-on.net/login")116 logger.Debug(page.MustInfo().URL)117 // page.MustScreenshotFullPage(fmt.Sprintf("screenshot/%s/%s-%s.png", yyMMddHHmm, "01-login", "01"))118 page.MustWaitLoad().MustElement("input[name=userId]").MustWaitVisible().MustInput(os.Getenv("USERID"))119 page.MustElement("input[name=userPwd]").MustWaitVisible().MustInput(os.Getenv("USERPW"))120 121 page.MustScreenshotFullPage(fmt.Sprintf("screenshot/%s/%s-%s.png", yyMMddHHmm, "01-login", "01"))122 page.MustElement("input[name=userPwd]").MustType(input.Enter)//.MustWaitInvisible()123 return page124}125func healthcare (page *rod.Page) {126 page.MustWaitLoad().MustNavigate("https://assist9.i-on.net/rb/main#booking/calendar?resourceId=555a0f1645cee1e334430183")127 logger.Debug(page.MustInfo().URL)128 page.MustWaitLoad().MustScreenshotFullPage(fmt.Sprintf("screenshot/%s/%s-%s.png", yyMMddHHmm, "02-healthcare", "01"))129 if page.MustWaitLoad().MustHas(".bg-color-blue") {130 page.MustWaitLoad().MustScreenshotFullPage(fmt.Sprintf("screenshot/%s/%s-%s.png", yyMMddHHmm, "02-healthcare", "02"))131 elements := page.MustElements(`div[class="fc-event fc-event-hori fc-event-start fc-event-end bg-color-blue"]`)132 elements.Last().MustClick()133 page.MustWaitLoad().MustElement(`a[class="btn btn-info btn-sm"]`).MustClick()134 logger.Info("%s", "Complate Healthcare")135 } else {136 logger.Warn("%s", "Not Found HealthCare")137 }138 page.MustScreenshotFullPage(fmt.Sprintf("screenshot/%s/%s-%s.png", yyMMddHHmm, "02-healthcare", "03"))139}140func lunch (page *rod.Page) {141 page.MustWaitLoad().MustNavigate("https://assist9.i-on.net/rb/main#booking/calendar?resourceId=554971d845ceac19504bbe46")142 logger.Debug(page.MustInfo().URL)143 page.MustWaitLoad().MustScreenshotFullPage(fmt.Sprintf("screenshot/%s/%s-%s.png", yyMMddHHmm, "03-lunch", "01"))144 if page.MustWaitLoad().MustHas(".bg-color-blue") {145 page.MustWaitLoad().MustScreenshotFullPage(fmt.Sprintf("screenshot/%s/%s-%s.png", yyMMddHHmm, "03-lunch", "02"))146 elements := page.MustElements(`div[class="fc-event fc-event-hori fc-event-start fc-event-end bg-color-blue"]`)147 elements.Last().MustClick()148 page.MustWaitLoad().MustElement(`a[class="btn btn-info btn-sm"]`).MustClick()149 logger.Info("%s", "Complate Lunch")150 } else {151 logger.Warn("%s", "Not Found Lunch")152 }153 page.MustScreenshotFullPage(fmt.Sprintf("screenshot/%s/%s-%s.png", yyMMddHHmm, "03-lunch", "03"))154}155func PrintCookies(browser *rod.Browser) {156 logger.Debug("%s", browser.MustVersion().UserAgent)...

Full Screen

Full Screen

browser.go

Source:browser.go Github

copy

Full Screen

...66}67func (b *Browser) MatchedPages() []*rod.Page {68 pageList := make([]*rod.Page, 0)69 for _, p := range b.MustPages() {70 if b.pageURLMatch.MatchString(p.MustInfo().URL) {71 pageList = append(pageList, p)72 }73 }74 return pageList75}76// TODO:remove me77func (b *Browser) ReloadPageByURL() error {78 b.DefaultViewport(&proto.EmulationSetDeviceMetricsOverride{Width: 1800, Height: 1200})79 for _, p := range b.MustPages() {80 u, err := b.pageURL(p)81 if err != nil {82 return errors.WithStack(err)83 }84 if b.pageURLMatch.MatchString(u.String()) {85 logrus.WithField("url", u.String()).Info("reload")86 // b.reloadPage(p)87 b.StorePage(p)88 }89 }90 return nil91}92func (b *Browser) Navigate(targetID string, pageURL string, waitSec int) error {93 // TODO: b.PageFromTarget !!94 for _, p := range b.MustPages() {95 if p.MustInfo().TargetID == proto.TargetTargetID(targetID) {96 wait := p.WaitRequestIdle(time.Second*time.Duration(waitSec), []string{}, []string{})97 if err := p.Navigate(pageURL); err != nil {98 return err99 }100 b.reloadPage(p, waitSec)101 wait()102 // html := innerHTML(p)103 // pp.Println(html)104 if err := b.StorePage(p); err != nil {105 return err106 }107 return nil108 }109 }110 return errors.Errorf("targetId == %s not exists", targetID)111}112func (b *Browser) PagesInfo() []*proto.TargetTargetInfo {113 res := make([]*proto.TargetTargetInfo, 0, 16)114 for _, p := range b.MustPages() {115 res = append(res, p.MustInfo())116 }117 return res118}119func (b *Browser) StorePage(p *rod.Page) error {120 html := innerHTML(p)121 u, err := b.pageURL(p)122 if err != nil {123 return errors.WithStack(err)124 }125 filename := b.PageMetaFilename(p, u)126 jsonBytes, err := json.MarshalIndent(127 struct {128 *url.URL129 PageURL string130 TargetID string131 BodyFilename string132 }{133 u,134 p.MustInfo().URL,135 string(p.MustInfo().TargetID),136 b.PageBodyFilename(p, u),137 },138 "", " ",139 )140 err = ioutil.WriteFile(filename, jsonBytes, 0644)141 if err != nil {142 // logrus.WithError(err).Error("write file")143 return errors.WithStack(err)144 }145 logrus.WithField("page filename", filename).Info("write")146 filename = b.PageBodyFilename(p, u)147 err = ioutil.WriteFile(filename, []byte(html), 0644)148 if err != nil {149 // logrus.WithError(err).Error("write file")150 return errors.WithStack(err)151 }152 logrus.WithField("page filename", filename).Info("write")153 return nil154}155func (b *Browser) PageBodyFilename(p *rod.Page, u *url.URL) string {156 return filepath.Join(options.PagePath(), fmt.Sprintf(157 "page_%s_%s_%s_body.html",158 u.Hostname(),159 strings.ReplaceAll(u.Path, "/", "__"),160 p.MustInfo().TargetID,161 ))162}163func (b *Browser) PageMetaFilename(p *rod.Page, u *url.URL) string {164 return filepath.Join(options.PagePath(), fmt.Sprintf(165 "page_%s_%s_%s_meta.json",166 u.Hostname(),167 strings.ReplaceAll(u.Path, "/", "_"),168 p.MustInfo().TargetID,169 ))170}171func (b *Browser) pageURL(p *rod.Page) (*url.URL, error) {172 // urlStr := p.MustEval("window.location.href").Result.String()173 return url.Parse(p.MustInfo().URL)174}175//TODO: err176func (b *Browser) reloadPage(p *rod.Page, waitSec int) error {177 logrus.WithField("url", p.MustEval("window.location.href").Result.String()).Info("reload")178 wait := p.WaitRequestIdle(time.Second*time.Duration(waitSec), []string{}, []string{})179 _, err := p.Eval("location.reload(true)")180 if err != nil {181 logrus.WithError(err).Error("eval")182 return err183 }184 wait()185 return nil186}187func innerHTML(p *rod.Page) string {...

Full Screen

Full Screen

ascii2d.go

Source:ascii2d.go Github

copy

Full Screen

...38 }39 page := stealth.MustPage(tool.Browser.RodBrowser)40 defer page.MustClose()41 page = page.MustNavigate(ascii2dURL).MustWaitLoad()42 if strings.Contains(page.MustInfo().Title, "Cloudflare") {43 log.Warningln("检测到Cloudflare,撞墙了")44 }45 page.MustElement("#file-form").MustSetFiles(path.Join(service.TempDirectory, fileName))46 page = page.MustElement("#file_upload > div > div.col-sm-1.col-xs-12 > button").MustClick().Page().MustWaitIdle()47 if strings.Contains(page.MustInfo().Title, "Cloudflare") {48 log.Warningln("检测到Cloudflare,撞墙了")49 }50 colorThumb := ascii2dURL + *page.MustElement(firstResultThumbnailSelector).MustAttribute("src")51 var colorURL *string52 if page.MustHas(firstResultURLSelector) {53 colorURL = page.MustElement(firstResultURLSelector).MustAttribute("href")54 } else {55 colorURL = &page.MustInfo().URL56 log.Debugln("色合搜索结果没有URL")57 }58 page = page.MustElement("body > div > div > div.col-xs-12.col-lg-8.col-xl-8 > div:nth-child(3) > div.detail-link.pull-xs-right.hidden-sm-down.gray-link > span:nth-child(2) > a").MustClick().Page().MustWaitIdle()59 if strings.Contains(page.MustInfo().Title, "Cloudflare") {60 log.Warningln("检测到Cloudflare,撞墙了")61 }62 bovwThumbnail := ascii2dURL + *page.MustElement(firstResultThumbnailSelector).MustAttribute("src")63 var bovwURL *string64 if page.MustHas(firstResultURLSelector) {65 bovwURL = page.MustElement(firstResultURLSelector).MustAttribute("href")66 } else {67 bovwURL = &page.MustInfo().URL68 log.Debugln("特征搜索结果没有URL")69 }70 log.Debugf("ascii2d搜索结果:\n色合:%s\n特征:%s\n", *colorURL, *bovwURL)71 return &Ascii2dResult{72 ColorThumbnail: colorThumb,73 ColorURL: *colorURL,74 BovwThumbnail: bovwThumbnail,75 BovwURL: *bovwURL,76 }77}...

Full Screen

Full Screen

MustInfo

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 browser := rod.New().MustConnect()4 fmt.Println(page.MustInfo().URL)5}6import (7func main() {8 browser := rod.New().MustConnect()9 page.MustElement("input").MustInput("Rod")10}11import (12func main() {13 browser := rod.New().MustConnect()14 page.MustElement("input").MustInput("Rod")15 page.MustElement("input").MustPress(rod.Enter)16}17import (18func main() {19 browser := rod.New().MustConnect()20 page.MustElement("input").MustInput("Rod")21 page.MustElement("input").MustPress(rod.Enter)22 page.MustElement("h3").MustClick()23}24import (25func main() {26 browser := rod.New().MustConnect()27 page.MustElement("input").MustInput("Rod")28 page.MustElement("input").MustPress(rod.Enter)29 page.MustElement("h3").MustClick()30 page.MustElement("a").MustClick()31}32import (33func main() {34 browser := rod.New().MustConnect()35 page.MustElement("input").MustInput("Rod")36 page.MustElement("input").MustPress(rod.Enter)37 page.MustElement("h

Full Screen

Full Screen

MustInfo

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 browser := rod.New().MustConnect()4 defer browser.MustClose()5 fmt.Println(page.MustInfo())6}7import (8func main() {9 browser := rod.New().MustConnect()10 defer browser.MustClose()11 fmt.Println(page.MustInfo())12}13import (14func main() {15 browser := rod.New().MustConnect()16 defer browser.MustClose()17 fmt.Println(page.MustInfo())18}19import (20func main() {21 browser := rod.New().MustConnect()22 defer browser.MustClose()23 fmt.Println(page.MustInfo())24}25import (26func main() {27 browser := rod.New().MustConnect()28 defer browser.MustClose()29 fmt.Println(page.MustInfo())30}31import (32func main() {33 browser := rod.New().MustConnect()34 defer browser.MustClose()35 fmt.Println(page.MustInfo())36}37import (38func main() {39 browser := rod.New().MustConnect()40 defer browser.MustClose()41 page := browser.MustPage("

Full Screen

Full Screen

MustInfo

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 browser := rod.New().MustConnect()4 defer browser.MustClose()5 defer page.MustClose()6 info := page.MustInfo()7 fmt.Println(info.URL)8}9import (10func main() {11 browser := rod.New().MustConnect()12 defer browser.MustClose()13 defer page.MustClose()14 page.MustWaitLoad()15 info := page.MustInfo()16 fmt.Println(info.URL)17}18import (19func main() {20 browser := rod.New().MustConnect()21 defer browser.MustClose()22 defer page.MustClose()23 page.MustWaitLoad()24 info := page.MustInfo()25 fmt.Println(info.URL)26 element := page.MustElement("input[name='q']")27 element.MustInput("rod")28}29import (30func main() {31 browser := rod.New().MustConnect()32 defer browser.MustClose()33 defer page.MustClose()34 page.MustWaitLoad()35 info := page.MustInfo()36 fmt.Println(info.URL)37 element := page.MustElement("input[name='q']")38 element.MustInput("rod")39 page.MustEval(`document.title`, &title)40 fmt.Println(title)41}42import (43func main() {44 browser := rod.New().MustConnect()45 defer browser.MustClose()46 defer page.MustClose()47 page.MustWaitLoad()48 info := page.MustInfo()49 fmt.Println(info.URL)50 element := page.MustElement("input[name='q']")51 element.MustInput("rod")52 page.MustEval(`document.title`, &

Full Screen

Full Screen

MustInfo

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(page.MustInfo())4}5import (6func main() {7 fmt.Println(page.MustElement("h1").MustText())8}9import (10func main() {11 fmt.Println(page.MustElement("h1").MustText())12}13import (14func main() {15 fmt.Println(page.MustElement("h1").MustText())16}17import (18func main() {19 fmt.Println(page.MustElement("h1").MustText())20}21import (22func main() {23 fmt.Println(page.MustElement("h1").MustText())24}25import (26func main() {27 fmt.Println(page.MustElement("h1").MustText())28}29import (30func main()

Full Screen

Full Screen

MustInfo

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 utils.E(utils.Touch("2.html"))4 browser := rod.New().MustConnect()5 defer browser.MustClose()6 fmt.Println("Title:", page.MustInfo().Title)7 fmt.Println("URL:", page.MustInfo().URL)8 fmt.Println("Last Navigation:", page.MustInfo().LastNavigation)9 fmt.Println("Last Navigation URL:", page.MustInfo().LastNavigation.URL)10 fmt.Println("Last Navigation Type:", page.MustInfo().LastNavigation.Type)11 fmt.Println("Last Navigation Redirect:", page.MustInfo().LastNavigation.Redirect)12 fmt.Println("Last Navigation Error:", page.MustInfo().LastNavigation.Error)13 fmt.Println("Last Navigation Error Text:", page.MustInfo().LastNavigation.ErrorText)14 fmt.Println("Last Navigation Error Description:", page.MustInfo().LastNavigation.ErrorDescription)15 fmt.Println("Last Navigation Error Failing URL:", page.MustInfo().LastNavigation.ErrorFailingURL)16 fmt.Println("Last Navigation Error Cancelable:", page.MustInfo().LastNavigation.ErrorCancelable)17 fmt.Println("Last Navigation Error Blocked URL:", page.MustInfo().LastNavigation.ErrorBlockedURL)18}19import (20func main() {21 utils.E(utils.Touch("3.html"))22 browser := rod.New().MustConnect()23 defer browser.MustClose()

Full Screen

Full Screen

MustInfo

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 r := rod.New().MustConnect()4 title := p.MustInfo().Title5 fmt.Println(title)6}

Full Screen

Full Screen

MustInfo

Using AI Code Generation

copy

Full Screen

1import (2type rod struct {3}4func (r *rod) Info() {5 fmt.Println("rod length: ", r.length)6}7func (r *rod) MustInfo() {8 fmt.Println("rod length: ", r.length)9}10func main() {11 r := &rod{length: 5}12 r.Info()13 r.MustInfo()14}15import (16type rod struct {17}18func (r *rod) Info() {19 fmt.Println("rod length: ", r.length)20}21func (r *rod) MustInfo() {22 fmt.Println("rod length: ", r.length)23}24func main() {25 r := &rod{length: 5}26 r.Info()27 r.MustInfo()28}29import (30type rod struct {31}32func (r *rod) Info() {33 fmt.Println("rod length: ", r.length)34}35func (r *rod) MustInfo() {36 fmt.Println("rod length: ", r.length)37}38func main() {39 r := &rod{length: 5}40 r.Info()41 r.MustInfo()42}43import (44type rod struct {45}46func (r *rod) Info() {47 fmt.Println("rod length: ", r.length)48}49func (r *rod) MustInfo() {50 fmt.Println("rod length: ", r.length)51}52func main() {53 r := &rod{length: 5}54 r.Info()55 r.MustInfo()56}57import (58type rod struct {59}60func (r *rod) Info() {61 fmt.Println("rod length: ", r.length)62}63func (r *rod) MustInfo() {64 fmt.Println("rod length: ", r.length)65}66func main() {

Full Screen

Full Screen

MustInfo

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 r := rod.New()4 info := r.MustInfo()5 fmt.Println(info)6}7import (8func main() {9 r := rod.New()10 info := r.MustInfo()11 fmt.Println(info)12}13import (14func main() {15 r := rod.New()16 info := r.MustInfo()17 fmt.Println(info)18}19import (20func main() {21 r := rod.New()22 info := r.MustInfo()23 fmt.Println(info)24}25import (26func main() {27 r := rod.New()

Full Screen

Full Screen

MustInfo

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 browser := rod.New().MustConnect()4 title := page.MustInfo().Title5 fmt.Println(title)6 browser.MustClose()7}

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Rod automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful