为什么硒webdriver火狐浏览器不为无特权用户工作? [英] Why is selenium webdriver Firefox not working for unpriviledged users?

查看:243
本文介绍了为什么硒webdriver火狐浏览器不为无特权用户工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用python在Django视图中使用selenium创建屏幕截图。硒火狐webdriver工作正常,如果我在根下启动它。但是,当我试图用非超级用户来运行它时试图实例化驱动程序冻结。 Django是通过apache www-data 用户调用的,所以它遇到了这个问题。



有没有办法使硒火狐webdriver作为非root?
$ b $从新鲜的Ubuntu 14.04安装我做了以下

  sudo apt-get install python-pip firefox xvfb 
pip install selenium pyvirtualdisplay
useradd testuser
$ b $然后在一个python shell中:

  from selenium import webdriver 
from pyvirtualdisplay import显示
display = Display(visible = 0,size =(800,600))
display.start()
driver = webdriver.Firefox()
driver.get(http://askubuntu.com)
print driver.page_source.encode('utf-8')
driver.quit()
display.stop()

如果我以root的身份登录到python,这个工作正常,如果我使用testuser帐户, driver = webdriver.Firefox()没有反应或错误。



我会很感激任何有关这种情况的建议。

在Linux上与Selenium + Firefox问题。问题是linux用户:为了运行这些测试,Firefox需要能够创建一个配置文件(一个Firefox的配置文件)。这个配置文件位于 user_home / .mozilla / firefox / profiles



所以在你的情况下,检查: / b>


  • 这位linux用户可以在自己的家里写信
  • etc / passwd 检查这个用户是否有一个默认的shell,例如 / bin / bash
  • 你的web应用程序所在的目录:如果所有文件都由 root 所有,请尝试 $ ls -larth ,您可以尝试更改此文件夹的权限,以允许非root用户访问它(然后允许运行Firefox + Selenium)。您还可以更改组的权限,并将root用户和非root用户添加到此组中


I am trying to use selenium to create screenshots in a Django view in python. The selenium firefox webdriver works well if I start it under root. However, when I try to run it with a non-superuser it freezes when trying to instantiate the driver. Django is called through the apache www-data user, so it suffers from that problem.

Is there any way to make the selenium firefox webdriver work as non-root?

From a fresh Ubuntu 14.04 install I did the following

sudo apt-get install python-pip firefox xvfb
pip install selenium pyvirtualdisplay
useradd testuser

And then in a python shell:

from selenium import webdriver
from pyvirtualdisplay import Display
display = Display(visible=0, size=(800, 600))
display.start()
driver = webdriver.Firefox()
driver.get("http://askubuntu.com")
print driver.page_source.encode('utf-8')
driver.quit()
display.stop()

If I log into python as root, this works fine, if I use the testuser account, the line driver = webdriver.Firefox() stales with no response or errors.

I would be thankful for any suggestions of why this is happening.

解决方案

I had the same issue with Selenium + Firefox on linux. The problem was the linux's user: to run these tests, Firefox need to be able to create a profile (a Firefox's profile). This profile is located at user_home/.mozilla/firefox/profiles

So in your case, check that :

  • This linux's user is allowed to write in his own home
  • In etc/passwd check that this user have a default shell, /bin/bash by example
  • In the directory where your webapp is: try a $ ls -larth: if all the files in this are owned by root, you can try to change the rights on this folder to allow you non-root users to access it (and then be allowed to run Firefox + Selenium). You can also change the rights to a group and add both root and non-root users to this group

这篇关于为什么硒webdriver火狐浏览器不为无特权用户工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆