Selenium python file cannot be executed in nodered

I created a python file to automatically press a button on a specific webpage by a message.

The sequence is as follows.

raspberry pi 4b

  1. sudo pip3 install selenium, sudo pip install selenium
  2. sudo apt-get install chromium-chromedriver
  3. The contents of the python file are as follows.

#!/usr/bin/python

import time
from selenium import webdriver
browser=webdriver.Chrome('/usr/lib/chromium-browser/chromeddriver')
url='https://www.naver.com'
browser.get(url)
click=browser.find_element_by_xpath("//*[@id='NM_darkmode_btn']")
click.click()
time. sleep(10)

This is by pressing the dark mode button on www.naver.com.

Actually when I run python naver.py in raspberry pi cmd it works very well.

However, it cannot be executed in nodered exec.

Can I know why?

For reference, it seems that other python files are not only related to selenium.

The red box in the image is the button that is automatically pressed.

Is this a continuation of your previous thread that you said was solved, or is it a different problem?

This is a continuation of this issue.
Actually, Python worked normally in cmd.

So, of course, I thought it would be Nordred.

But strangely, only selenium python code does not work with exec.

  1. In what way does it not work?

  2. If you run it from an ssh shell does it work?

It works fine in raspberry pi cmd.
For example, when running in cmd, the browser opens and the button is clicked.

However, nothing happens when used in nodered.

That isn't what I asked. Are you running an ssh shell into the pi or are you running it on a keyboard/display plugged into the pi?

I think it unlikely that nothing happens, it is just that what you hoped for does not happen. In your previous thread I suggested connecting debug nodes set to show Complete Message to all outputs of the exec node and looking to see what they show. Did you do that?

If run as a service node-red in the background won’t have a display attached so it won’t be able to open the browser etc. You may be able to add a DISPLAY setting to the command.

A keyboard and display connected to the Pi.

I am trying to enter the display command, what should I do?

For example

/usr/bin/python /home/pi/naver.py display

Should I do this?

No, it should be something like
DISPLAY=:1 usr/bin/python /home/pi/naver.py
or perhaps :0, it is not easy to predict which virtual display will work.

That was why I asked whether it worked from an ssh shell, which you apparently ignored, as that would exhibit the same issue, if this is indeed the problem.

It's the weekend, so I'll try it on Monday. thank you.

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