selenium-ide
selenium-ide copied to clipboard
WS : Websocket to get StoredVars
🚀 Feature Proposal
I managed to make call on Selenium IDE from python using WebSocket. We make the websoket on the url available here http://127.0.0.1:8315/json
We can make a lot of things, but currently we didn't find a way to get the values of the StoredVars
Motivation
Using Selenium IDE api is very usefull. And currently we can't ready stored Variables by a websocket call ...
We need to have something like : window.sideAPI.variables.getAll() and window.sideAPI.variables.get('VARNAME')
If we can set variables directly it can be great too ...
Example
import asyncio import websockets import json
async def send_command(): uri = "ws://127.0.0.1:8315/devtools/page/1AC762E0E631389A7B1983635436BD96" async with websockets.connect(uri) as websocket: print("Connected to the WebSocket server")
Envoyer la commande pour exécuter window.sideAPI.state.get()
command = {
"id": 1,
"method": "Runtime.evaluate",
"params": {
"expression": "window.sideAPI.variables.getAll()"
}
}
await websocket.send(json.dumps(command))
# Recevoir la réponse initiale du serveur
response = await websocket.recv()
response_data = json.loads(response)
print("Received initial response:", response_data)
asyncio.run(send_command())
So far I have not found a solution to pass external values to the SIDE file. Issue 1854
Here is my first solution:
Unfortunately, the use of defined values outside the script such as "se_username" or "se_password" from the SIDE file does not work. However, if these are defined within the script, you will receive the values that you can continue to use:
executeScript
{
"command": "executeScript",
"target": "var xhr = new XMLHttpRequest(); var queryVar = 'se_username'; var IDName = 'abcdefg'; var queryURL = http://192.168.1.1/se/${IDName}/getValue/${queryVar}; var username = 'username'; var password = 'password'; var authHeader = 'Basic ' + btoa(username + ':' + password); xhr.open('POST', queryURL, false); xhr.setRequestHeader('Content-Type', 'application/json'); xhr.setRequestHeader('Authorization', authHeader); xhr.send(JSON.stringify({ IDName: IDName })); if (xhr.status === 200) { return JSON.parse(xhr.responseText)[queryVar]; \tconsole.log('Username retrieved:', queryVar); } else { throw new Error('Failed to fetch config'); }",
"value": "se_username",
"id": "7a369bf1-d4c1-4ee8-a304-22baf09878bd"
},
{
"command": "executeScript",
"target": "var xhr = new XMLHttpRequest(); var queryVar = 'se_password'; var IDName = 'abcdefg'; var queryURL = http://192.168.1.1/1/se/${IDName}/getValue/${queryVar}; var username = 'username'; var password = 'password'; var authHeader = 'Basic ' + btoa(username + ':' + password); xhr.open('POST', queryURL, false); xhr.setRequestHeader('Content-Type', 'application/json'); xhr.setRequestHeader('Authorization', authHeader); xhr.send(JSON.stringify({ IDName: IDName })); if (xhr.status === 200) { return JSON.parse(xhr.responseText)[queryVar]; \tconsole.log('Username retrieved:', queryVar); } else { throw new Error('Failed to fetch config'); }",
"value": "se_password",
"id": "080ecb23-e88b-4ba5-9b76-fabb327de323"
},
{
"command": "echo",
"target": "Username retrieved: ${se_username}, Password retrieved: ${se_password}",
"value": "",
"id": "ce808878-4b1a-41b3-a75e-cbfb0048a332"
},
... debug: executing echo|Username retrieved: ${se_username}, Password retrieved: ${se_password} info: echo: Username retrieved: myuser, Password retrieved: mypass ...
Attempts with Node.js server and this script only returned the first value. After switching to a high-performance Apache with PHP, the values are delivered without any problems.
executeAsyncScript
Multiple attempts to convert this script to async script "executeAsyncScript" have failed:
JavascriptError: javascript error: Unexpected token '.'
JavaScript stack:
SyntaxError: Unexpected token '.'
at new Function (
Can someone try to change this script to an asyc-script which works with "executeAsyncScript"?
This is super friggin awesome. I'm sorry, I'm going through a phase of my life where I'm just sleeping 11 hours a night. Normally I'd be all about getting it working with you, but I basically just don't have it at this point in my life. I'm hoping I find the motivation again soon, but mostly these days I just sleep.
@toddtarsi hope you are better now ;-)
@spea1 i don't see how you get information from SIDE, do you have a details sample on how to get StoredVars ?
For WebSocket from Python in don't know the location of StoredVars, but I can display a lot of information with this sample script
get_get_promise.py.txt
@AlphonseProffit : with 'command: executeScript' from SIDE file I ask the Apache. The values can be in an encrypted file, KeePass or in a database. php.txt