# Selenium python file cannot be executed in nodered

**URL:** https://discourse.nodered.org/t/selenium-python-file-cannot-be-executed-in-nodered/48694
**Category:** General
**Created:** [21 July 2021 08:36 UTC](https://discourse.nodered.org/t/selenium-python-file-cannot-be-executed-in-nodered/48694 "2021-07-21T08:36:08Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![Athurian](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@Athurian](https://discourse.nodered.org/u/Athurian)
#### Post date: [21 July 2021 08:36 UTC](https://discourse.nodered.org/t/selenium-python-file-cannot-be-executed-in-nodered/48694/1 "2021-07-21T08:36:08Z")

</div>

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](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](http://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.

 ![11111](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/c/dcf88485ac6f64e4f02d837efb806547c43ea509.png)

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [21 July 2021 20:29 UTC](https://discourse.nodered.org/t/selenium-python-file-cannot-be-executed-in-nodered/48694/2 "2021-07-21T20:29:37Z")

</div>

Is this a continuation of your [previous thread](https://discourse.nodered.org/t/python-file-cannot-be-executed-with-exec-node/48620) that you said was solved, or is it a different problem?

---

<div class="post-metadata">

### Author: ![Athurian](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@Athurian](https://discourse.nodered.org/u/Athurian)
#### Post date: [22 July 2021 01:53 UTC](https://discourse.nodered.org/t/selenium-python-file-cannot-be-executed-in-nodered/48694/3 "2021-07-22T01:53:05Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [22 July 2021 06:17 UTC](https://discourse.nodered.org/t/selenium-python-file-cannot-be-executed-in-nodered/48694/4 "2021-07-22T06:17:19Z")

</div>

1. In what way does it not work?

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

---

<div class="post-metadata">

### Author: ![Athurian](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@Athurian](https://discourse.nodered.org/u/Athurian)
#### Post date: [22 July 2021 08:11 UTC](https://discourse.nodered.org/t/selenium-python-file-cannot-be-executed-in-nodered/48694/5 "2021-07-22T08:11:08Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [22 July 2021 13:27 UTC](https://discourse.nodered.org/t/selenium-python-file-cannot-be-executed-in-nodered/48694/6 "2021-07-22T13:27:29Z")

</div>

> [@Athurian](#):
>
> It works fine in raspberry pi cmd.

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?

> [@Athurian](#):
>
> nothing happens when used in nodered.

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?

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [22 July 2021 13:59 UTC](https://discourse.nodered.org/t/selenium-python-file-cannot-be-executed-in-nodered/48694/7 "2021-07-22T13:59:50Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Athurian](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@Athurian](https://discourse.nodered.org/u/Athurian)
#### Post date: [23 July 2021 00:56 UTC](https://discourse.nodered.org/t/selenium-python-file-cannot-be-executed-in-nodered/48694/8 "2021-07-23T00:56:35Z")

</div>

> [@dceejay](#):
>
> 백그라

A keyboard and display connected to the Pi.

---

<div class="post-metadata">

### Author: ![Athurian](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@Athurian](https://discourse.nodered.org/u/Athurian)
#### Post date: [23 July 2021 01:25 UTC](https://discourse.nodered.org/t/selenium-python-file-cannot-be-executed-in-nodered/48694/9 "2021-07-23T01:25:04Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [23 July 2021 16:28 UTC](https://discourse.nodered.org/t/selenium-python-file-cannot-be-executed-in-nodered/48694/10 "2021-07-23T16:28:39Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Athurian](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@Athurian](https://discourse.nodered.org/u/Athurian)
#### Post date: [24 July 2021 05:25 UTC](https://discourse.nodered.org/t/selenium-python-file-cannot-be-executed-in-nodered/48694/11 "2021-07-24T05:25:19Z")

</div>

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

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [22 September 2021 05:26 UTC](https://discourse.nodered.org/t/selenium-python-file-cannot-be-executed-in-nodered/48694/12 "2021-09-22T05:26:13Z")

</div>

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