简体   繁体   English

如何从 bash 文件运行 selenium 脚本

[英]how to run selenium script from a bash file

I have a windows laptop in which i have written a selenium script written in python which creates a github repository.我有一台 windows 笔记本电脑,我在其中编写了一个用 python 编写的 selenium 脚本,它创建了一个 github 存储库。 It works fine when a run the python file but it gives error when i try to run the script from a bash file.当运行 python 文件时它工作正常但是当我尝试从 bash 文件运行脚本时它会出错。 what should i do我应该怎么办

my bash file:我的 bash 文件:

python3 login.py 

my python file which i am calling from bash:我从 bash 调用的 python 文件:

def login():
    chr_options = Options()
    chr_options.add_experimental_option("detach", True)

    driver = webdriver.Chrome(ChromeDriverManager().install(), options=chr_options)

    driver.get('https://github.com/new')

this is what i get when i try to run the python file with bash from my ubuntu terminal and i have a windows machine and the python file works fine when i try to run it from the windows terminal这是我尝试从 ubuntu 终端运行 python 文件时得到的结果

selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binaryStacktrace:#0 0x55de662442a3
 <unknown>#1 0x55de66002f77 
<unknown>#2 0x55de66029047
 <unknown>#3 0x55de660277d0 <unknown>#4 0x55de660680b7 <unknown>#5 0x55de66067a5f <unknown>#6 0x55de6605f903 <unknown>#7 0x55de66032ece <unknown>#8 0x55de66033fde <unknown>#9 0x55de6629463e <unknown>#10 0x55de66297b79 <unknown>#11 0x55de6627a89e <unknown>#12 0x55de66298a83 <unknown>#13 0x55de6626d505 <unknown>#14 0x55de662b9ca8 <unknown>#15 0x55de662b9e36 <unknown>#16 0x55de662d5333 <unknown>#17 0x7f87539e4b43 <unknown>

i have a windows 10 laptop in which my selenium script works fine, but when i run the file through the bash terminal it gives this error我有一台 windows 10 笔记本电脑,我的 selenium 脚本在其中工作正常,但是当我通过 bash 终端运行文件时,出现此错误

selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary
Stacktrace:
#0 0x55de662442a3 <unknown>
#1 0x55de66002f77 <unknown>
#2 0x55de66029047 <unknown>
#3 0x55de660277d0 <unknown>
#4 0x55de660680b7 <unknown>

When you run the python file in windows it uses Chrome installed in you Windows machine, but when you work in a bash terminal you do it on a Linux machine that runs as a virtual machine in you Windows.当您在 windows 中运行 python 文件时,它使用安装在您 Windows 机器中的 Chrome,但是当您在 bash 终端中工作时,您在 Linux 机器上执行此操作,该机器在您 Windows 中作为虚拟机运行。
So it is a separate machine and it cannot use Chrome from your Windows. It needs to have its own Chrome.所以它是一台单独的机器,它不能使用你的 Windows 的 Chrome。它需要有自己的 Chrome。 Additionally this virtual machine does not have a GUI so you will need to run selenium in the headless mode.此外,此虚拟机没有 GUI,因此您需要在headless模式下运行 selenium。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM