seleniumbase / SeleniumBase

📊 Python's all-in-one framework for web crawling, scraping, testing, and reporting. Supports pytest. UC Mode provides stealth. Includes many tools.
https://seleniumbase.io
MIT License
5.16k stars 958 forks source link

Exporting recorded script to json #2728

Closed Ashish3080 closed 5 months ago

Ashish3080 commented 5 months ago

Hi, I am using seleniumbase to record actions on my browser. It works fine and generates a script having all the steps followed during the recording. I want to export all the actions and the subsequent element id/URL/texts into a json file. How can I do that? I am using sbase mkrec new_test_1.py --url=imdb.com to create test files to test the recordings

mdmintz commented 5 months ago

For a JSON file (instead of an SB-runnable Python script), record your script with the Chrome DevTools Recorder (included with Chrome). To reach it, View -> Developer -> Developer Tools. Or Right-Click -> Inspect.

Screenshot 2024-04-29 at 10 18 07 AM

Alternatively, you could create your own Python script that parses out the items from an existing SB Python file into JSON, but it's probably much easier to just use the built-in Chrome DevTools Recorder, which has an option to export recordings into JSON. If the Chrome Recorder tab isn't visible by default, you may need to click a checkbox from the configuration/settings section.

Ashish3080 commented 5 months ago

Is there a way to stop the recording other than entering 'c' on the terminal. Like a shortcut key like 'esc'?

mdmintz commented 5 months ago

@Ashish3080 That's a Python breakpoint(). c + Enter to continue, but you can check the Python docs for more.