Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How i can evaluate an ASYNC script in cdp mode? #3553

Answered by mdmintz
jvitormelo asked this question in Q&A
Discussion options

In the normal mode, I have the self.execute_async_script(script, timeout=None)

But when using CDP I only have the sb.cdp.evaluate(expression)

How I can await a Promise from a script using cdp mode?

You must be logged in to vote

See the async example for utilizing await: SeleniumBase/examples/cdp_mode/raw_async.py:

async def main():
driver = await cdp_driver.cdp_util.start_async()
page = await driver.get("about:blank")
await page.set_locale("en")
await page.get("https://www.priceline.com/")

You have to stay in the same tab for CDP Mode.
If you want to switch between tabs, you have to reconnect the driver with sb.connect() first.
Here are a few examples that mix CDP Mode with WebDriver to do that:

Replies: 2 comments

Comment options

image
And one more question, I was trying to reutilize the same browser and open new tabs, but after activating cdp mode, it will not open a new tab.

Is this intended?

You must be logged in to vote
0 replies
Comment options

See the async example for utilizing await: SeleniumBase/examples/cdp_mode/raw_async.py:

async def main():
driver = await cdp_driver.cdp_util.start_async()
page = await driver.get("about:blank")
await page.set_locale("en")
await page.get("https://www.priceline.com/")

You have to stay in the same tab for CDP Mode.
If you want to switch between tabs, you have to reconnect the driver with sb.connect() first.
Here are a few examples that mix CDP Mode with WebDriver to do that:

You must be logged in to vote
0 replies
Answer selected by mdmintz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /