Working with Selenium IDE

Hello all,

I have created a script using Selenium IDE that auto logins to a webpage and retrieves some information. Per the instructions I have downloaded the Selenium Side Runner (also known as Command Line Runner) tool that allows one to execute a project script from the command line.

I am able to execute my script properly with no errors when using the command
selenium-side-runner /path/to/file.side

However, when I try to use an exec node to call this same command, it returns an error.

FAIL ../../usr/lib/node_modules/selenium-side-runner/dist/main.test.js
  Running project reportGen
    ✕ Running test SafetySkills (785 ms)

  ● Running project reportGen › Running test SafetySkills

    WebDriverError: unknown error: Chrome failed to start: exited abnormally.
      (unknown error: DevToolsActivePort file doesn't exist)
      (The process started from chrome location /usr/bin/chromium-browser is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

      at Object.throwDecodedError (node_modules/selenium-webdriver/lib/error.js:524:15)
      at parseHttpResponse (node_modules/selenium-webdriver/lib/http.js:587:13)
      at Executor.execute (node_modules/selenium-webdriver/lib/http.js:515:28)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        2.385 s, estimated 4 s
Ran all test suites within paths "/usr/lib/node_modules/selenium-side-runner/dist/main.test.js".

I know there are a couple of Selenium node packages available and each one has a detail about downloading a webdriver. I downloaded the chrome driver detailed in the Selenium Command-Line Runner instructions. However, the npm install -g chromedriver returned an error that it is only supported for 64 bit.

I used the instructions found here to install the chromedriver and as I said, it worked properly when running the script from the command line of the rpi.

My goal is to be able to activate this script from node-RED, I realize there is probably multiple ways to do this, but I would like to focus solely on being able to run the script I have already created. It has a .side extension by the way. I have a couple of questions to maybe narrow down suggestions:

  1. Since the issue appears to be with activating chrome from node-RED, do I need a different chromedriver?
  2. Do the Selenium nodes' "run script" node run a .side file or is that executing a script from the webpage?
  3. It appears the Selenium-Side-Runner is based on Node.js which made me think the compatibility would be easy with Node-RED. Is there a way to run the .side file from something more native to Node.js?

Cant help with selenium but just in case you are not aware - it is quite likely there could be a simpler approach - where you access the data directly (assuming it is an API providing it)

I appreciate the response, I tried that first via an http request but I believe I was being blocked by security. I have really enjoyed using the Selenium IDE so far so I would like to pursue this issue further. I'm just surprised that it works from the native command line, but not the exec node.

I actually have another forum post where I provide more details about my attempt using an http request if you are interested.

Just an update I'd like to share:

  1. I tried placing the selenium command inside a bash script and calling the bash script from node-RED and that had the same effect.

  2. I tried installing firefox and using the geckodriver and the geckodriver installed via npm no problem, unlike the chromedriver. I use this command to tell side runner to use firefox:
    selenium-side-runner -c "browserName=firefox" /path/to/file.side

  3. However, this produces an error even running from the native command line of the Pi. But it's a different error.

***@*******:~ $ selenium-side-runner -c "browserName=firefox" /home/***/Desktop/reportGen.side
  console.info
    
          Project reportGen doesn't have any suites matching filter .*,
          attempting to iterate all tests in project

      at src/main.test.ts:155:15
          at Array.forEach (<anonymous>)

info: Running test SafetySkills
info: Building driver for firefox
  console.error
    Error: Server terminated early with status 2
        at /usr/lib/node_modules/selenium-side-runner/node_modules/selenium-webdriver/remote/index.js:252:24
        at processTicksAndRejections (node:internal/process/task_queues:96:5)

      at src/run.ts:128:19

 FAIL  ../../usr/lib/node_modules/selenium-side-runner/dist/main.test.js
  Running project reportGen
    âś• Running test SafetySkills (558 ms)

  ● Running project reportGen › Running test SafetySkills

    Server terminated early with status 2

      at node_modules/selenium-webdriver/remote/index.js:252:24

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        2.888 s
Ran all test suites within paths "/usr/lib/node_modules/selenium-side-runner/dist/main.test.js"

Hopefully someone can offer some assistance or something for me to try. It is frustrating that the chrome version works on command line, but not in Node-RED. I'm assuming it's a permission or pathing issue, but I really don't know.

Yes, that is common and has been done with http request many many times. However you didn't follow up with any details and instead headed down the selenium path - that's why there was no solution offered.

I believe I posted the output of the http request. I don't know html well enough to comb through and see what sort of security issues I was running into. So when I found Selenium as an alternative tool it appeared easier for me at the moment.

And it is. Selenium IDE and the Side-Runner are both up and running quickly and work very well. But I'm being stubborn and want to be able to call the script from Node-RED. I could simply use the crontab tool to schedule it to run at a certain time each day, or I could even ditch the Selenium IDE route and work with the Selenium node packages.

But I'm wanting to figure out what is the hang up between the command line and the exec node. It seems what I'm trying to do should work.

If you think it will be easier to return to the http request route I'm not opposed to sharing more information on the other thread, I'm just not sure where to look.

I have altered this comment as it just made things more confusing. See solution(s) below.

I was able to solve my original problem. I was actually able to get Selenium working in three different ways. I will describe each separately, prepare for a long post.

  1. Selenium Nodes - node-red-contrib-simple-webdriver
    This was the easiest to solve but the hardest to find an answer to. This should pertain to the following packages too:
    node-red-contrib-wd2
    node-red-contrib-webdriver
    The answer was to manually start chromedriver. In the command line on your device, type "chromedriver". The default port is 9515 so in the "Open URL" node just make sure your "server" is pointed to port 9515. If it is running on localhost then http://localhost:9515 for example.
    Then the nodes work great!

  2. Selenium Side Runner
    This was my original question and I ended up solving it by compiling information from several sources. The bottom line is that when Node-RED is ran from a remote comuputer it appears it is similar to accessing the Pi from ssh. Therefore a "display" or virtual display session needs to be running. I was simply able to add a modifier to my exec node command:
    DISPLAY=:0 selenium-side-runner /path/to/file.side
    The exact display number will vary based on several factors but you can google if you want to know more.

  3. Python Script
    This one is very similar to solution #2. There once again needs to be a display specified to call from a remote connection. There are 2 ways to solve this specific scenario:
    a. Slightly different parameter than above in an exec node:
    DISPLAY=:0.0 python3 /path/to/file.py
    or
    b. Add a couple of lines in your python script:
    import os
    os.environ.__setitem__('DISPLAY', ':0.0')

Now each of these methods are working correctly and they all have their advantages. Hopefully this will help someone in the future if you find yourself having the same problems I did. If the thread is still open I would be happy to help if I can.

Cheers and happy noding,

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.