This bookmarklet allows you to record your interactions on a webpage (clicks and other actions) and then generate a Python Selenium script to mimic those actions. It's a powerful tool for automating repetitive web tasks, creating test scripts, or simply documenting user flows.
- Record Clicks: Captures all your mouse clicks on interactive elements.
- Track Actions: (You may want to elaborate on what "other actions" are here. For example: "Tracks form input, scrolling, and navigation.")
- Generate Selenium Script: Automatically creates a runnable Python Selenium script to replay the recorded actions.
- Bookmarklet Convenience: Easily activate the recording directly from your browser's bookmarks bar.
To install, simply drag the following link to your browser's bookmarks bar:
[Record Web Actions](javascript:(function(){/* Your bookmarklet code will go here */})())
Note: You'll need to replace /* Your bookmarklet code will go here */ with your actual JavaScript bookmarklet code.
- Navigate to the webpage where you want to record actions.
- Click on the "Record Web Actions" bookmarklet in your bookmarks bar.
- A recording indicator (e.g., a small floating icon, a console message) should appear, letting you know that recording has started.
Interact with the webpage as you normally would. Click on buttons, fill out forms, navigate to different pages – all your actions will be tracked.
- To stop recording, click the "Record Web Actions" bookmarklet again.
- Upon stopping, the generated Python Selenium script will be displayed. (You'll need to specify how it's displayed, e.g., in a new tab, a pop-up, or copied to the clipboard.)
- Option 1 (Common): The script is copied to your clipboard, and a notification appears.
- Option 2: A new tab opens displaying the script, allowing you to copy it.
- Option 3: A downloadable
.pyfile is generated.
- Copy the script and save it as a
.pyfile (e.g.,recorded_actions.py).
To run the generated Python script, you'll need to have Python and the Selenium library installed.
- Python 3.x: Download from python.org.
- Selenium Library: Install via pip:
pip install selenium
- WebDriver: You'll need a WebDriver for your browser (e.g., ChromeDriver for Chrome, GeckoDriver for Firefox). Download it and ensure it's in your system's PATH or specify its location in your Python script.
- Open your terminal or command prompt.
- Navigate to the directory where you saved your
.pyscript. - Run the script:
python recorded_actions.py
The script will launch your browser and mimic the actions you recorded.
The bookmarklet injects JavaScript into the current page. This JavaScript listens for DOM events (like click, input, etc.), logs them, and stores relevant information (e.g., CSS selectors, text content). When recording stops, this logged data is then formatted into a Python Selenium script using pre-defined templates.
- More Action Types: Support for drag-and-drop, right-clicks, keyboard shortcuts.
- Error Handling: Add more robust error handling to the generated Selenium scripts.
- Conditional Logic: Allow users to insert simple conditional statements into their recorded flow.
- Parameterization: Enable easy modification of input values in the generated script.
- UI for Recording: A small, non-intrusive UI element on the page to start/stop recording and show status.
- Script not generating: Ensure your bookmarklet code is correct and the browser's JavaScript console doesn't show any errors.
- Selenium script failing:
- Check if the WebDriver path is correct.
- Verify that the elements (buttons, input fields) on the page haven't changed their structure (e.g., CSS classes, IDs) since recording. Webpages are dynamic!
- Add
time.sleep()statements in the generated script if elements are taking too long to load.
- Bookmarklet not working: Some websites might have Content Security Policies (CSPs) that prevent bookmarklets from executing certain scripts.
Feel free to suggest improvements or contribute to the development of this bookmarklet!
(Add your chosen license here, e.g., MIT, Apache 2.0, etc.)