Skip to content
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

WS : Websocket to get StoredVars #1855

Open
AlphonseProffit opened this issue Aug 12, 2024 · 4 comments
Open

WS : Websocket to get StoredVars #1855

AlphonseProffit opened this issue Aug 12, 2024 · 4 comments

Comments

@AlphonseProffit
Copy link

🚀 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())

@spea1
Copy link

spea1 commented Aug 14, 2024

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"?

@toddtarsi
Copy link
Contributor

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.

@AlphonseProffit
Copy link
Author

AlphonseProffit commented Oct 17, 2024

@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

@spea1
Copy link

spea1 commented Nov 26, 2024

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants