简体   繁体   English

py2app硒不安装Firefox

[英]py2app selenium without firefox install

I am wondering if there is a way within py2app to include the Firefox browser, or if there is a way for Selenium to use Firefox without having to install Firefox on the host machine. 我想知道py2app中是否可以包含Firefox浏览器,或者Selenium是否可以使用Firefox而不必在主机上安装Firefox。

I have created an app with py2app that uses Selenium, however, I have Firefox installed on my machine, but not everyone that will receive the app will have Firefox installed. 我已经使用py2app创建了一个使用Selenium的应用程序,但是,我在计算机上安装了Firefox,但是并非每个将收到该应用程序的人都将安装Firefox。 I am looking for a way to either include Firefox in the distribution or go around this. 我正在寻找一种在发行版中包含Firefox或解决这个问题的方法。

Script will not run if Firefox is not preinstalled. 如果未预装Firefox则脚本不会运行。 You can test your script with other browser, for example Chrome. 您可以使用其他浏览器(例如Chrome)测试脚本。 If it works on Chrome also, then you can edit script like this: 如果它也可以在Chrome上运行,则可以编辑如下脚本:

from selenium.common.exceptions import WebDriverException
try:
    driver = webdriver.Firefox()
except WebDriverException:
    driver = webdriver.Chrome()

You can add same for few more browsers (IE, Opera, Safari...) to be sure that script will run on users machine 您可以为更多浏览器(IE,Opera,Safari ...)添加相同的代码,以确保该脚本将在用户计算机上运行

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

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