Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NODRIVER] Nodriver uses click to enter a new page, how to switch and control this new page #2108

Open
pythonlw opened this issue Dec 18, 2024 · 0 comments

Comments

@pythonlw
Copy link

pythonlw commented Dec 18, 2024

async def main1():
    config = uc.Config()
    config.host = "127.0.0.1"
    config.port = 62805
    browser_args = ['--no-sandbox', '--window-size=1020,1080', '--disable-infobars',
                    '--disable-web-security', '--disable-site-isolation-trials',
                    '--disable-search-engine-choice-screen',
                    '--no-default-browser-check',
                    '--no-first-run',
                    '--disable-default-apps',
                    '--disable-popup-blocking',
                    '--disable-extensions',
                    f"--proxy-server=http://127.0.0.1:10809"]

    driver = await uc.start(
        # config=config,
        # browser_args=browser_args
                            )

    main_tab = driver.main_tab
    page = await main_tab.get('https://www.bing.com')
    input_text = await page.select('input[id="sb_form_q"]')
    await input_text.send_keys('python')
    await input_text.clear_input()
    await input_text.send_keys('python')
    await page.sleep(2)

    search = await page.find('//label[@id="search_icon"]', best_match=True)
    await search.click()
    await page.sleep(3.5)

    thing_input = await page.select("a[href^='https://python.p2hp.com']")
    attrs = thing_input.attrs
    print('attrs:', attrs)

    divs1 = await page.find_all('//li[contains(@class, "b_algo")]//h2//a[@target="_blank"]')
    print('divs1:', len(divs1))

    if len(divs1) > 0:
        await divs1[0].click()  # enter a new navigation page

    await page.sleep(5)
    # How to control this new page
    print(page.target.url)

uc.loop().run_until_complete(main1())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant