-
-
Notifications
You must be signed in to change notification settings - Fork 430
Open
Labels
questionQuestions related to rodQuestions related to rod
Description
Rod Version: v0.116.2
package main
import (
"log"
"time"
"github.com/go-rod/rod"
"github.com/go-rod/rod/lib/launcher"
)
func main() {
url := launcher.New().Headless(false).MustLaunch()
browser := rod.New().ControlURL(url).MustConnect()
page1 := browser.MustPage("https://www.baidu.com")
page2 := browser.MustPage("https://www.baidu.com")
go func() {
page1.MustWaitLoad()
page1.MustElement("#kw").MustInput("123")
page1.MustElement("#su").MustClick()
page1.MustWaitNavigation()
time.Sleep(2 * time.Second)
title := page1.MustEval(`() => document.title`).String()
log.Println("Page 1 title:", title)
}()
go func() {
page2.MustWaitLoad()
page2.MustElement("#kw").MustInput("345")
page2.MustElement("#su").MustClick()
page2.MustWaitNavigation()
time.Sleep(2 * time.Second)
title := page2.MustEval(`() => document.title`).String()
log.Println("Page 2 title:", title)
}()
select {}
}const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch({ headless: false });
const context = await browser.newContext();
const page1 = await context.newPage();
await page1.goto('https://www.baidu.com');
const page2 = await context.newPage();
await page2.goto('https://www.baidu.com');
await page1.fill('input[name="wd"]', '123');
await page1.keyboard.press('Enter');
await page1.waitForSelector('#content_left');
await page2.fill('input[name="wd"]', '456');
await page2.keyboard.press('Enter');
await page2.waitForSelector('#content_left');
const result1 = await page1.$eval('#content_left .result h3', el => el.innerText);
console.log('123Result:', result1);
const result2 = await page2.$eval('#content_left .result h3', el => el.innerText);
console.log('456Result:', result2);
await new Promise(resolve => setTimeout(resolve, 20000));
await browser.close();
})();I want to operate multiple tabs at the same time, How to use Rod to achieve this?
Playwright is operable
Metadata
Metadata
Assignees
Labels
questionQuestions related to rodQuestions related to rod