-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Use SeleniumBase with already opened Chrome by remote debugging address #3354
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
Comments
I was about to ask a similar question, would like this to run on a browser session with WhatsApp logged in, so I can read a public group messages... That would be awesome. |
That's doable if you already know the Here's an import asyncio
from seleniumbase.undetected.cdp_driver import cdp_util
async def main():
host = "127.0.0.1"
port = 9222
driver = await cdp_util.start_async(host=host, port=port)
page = await driver.get("https://seleniumbase.io/")
await asyncio.sleep(2)
print(await page.evaluate("document.title"))
element = await page.find("CDP Mode")
await element.click_async()
await asyncio.sleep(2)
print(await page.evaluate("document.title"))
if __name__ == "__main__":
asyncio.run(main()) If you're unfamiliar with import asyncio
import time
from seleniumbase.undetected.cdp_driver import cdp_util
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
host = "127.0.0.1"
port = 9222
driver = loop.run_until_complete(cdp_util.start(host=host, port=port))
page = loop.run_until_complete(driver.get("https://seleniumbase.io/"))
time.sleep(2)
print(loop.run_until_complete(page.evaluate("document.title")))
element = loop.run_until_complete(page.find("CDP Mode"))
loop.run_until_complete(element.click_async())
time.sleep(2)
print(loop.run_until_complete(page.evaluate("document.title"))) And here's the simplified SB-CDP sync format for that: import asyncio
from seleniumbase.core import sb_cdp
from seleniumbase.undetected.cdp_driver import cdp_util
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
host = "127.0.0.1"
port = 9222
driver = loop.run_until_complete(cdp_util.start(host=host, port=port))
page = loop.run_until_complete(driver.get("https://seleniumbase.io/"))
sb = sb_cdp.CDPMethods(loop, page, driver)
sb.sleep(2)
print(sb.get_title())
sb.click("CDP Mode")
sb.sleep(2)
print(sb.get_title()) Those examples use pure CDP: Note that you'll get errors running those examples if there's no active Chrome instance with the debug |
any solution to connect SeleniumBase with already opened Chrome by remote debugging address
Example in selenium:
The text was updated successfully, but these errors were encountered: