duanjiao8007 2013-08-17 02:11 采纳率: 100%
浏览 183
已采纳

Python:无法通过脚本启动Selenium Webdriver(Firefox),但它可以通过命令行工作

Title says it all. I'm using webdriver on a remote webserver without a GUI. From the command line, I can do this and everything works fine:

from selenium import webdriver
from pyvirtualdisplay import Display
display = Display(visible=0, size=(800,600))
display.start()
browser = webdriver.Firefox()

I.e., I can navigate the web, get urls, get source code, and everything else with the browser instance. But trying to execute a script on the server containing the same lines doesn't work. It might be relevant that the script is executed via PHP. Everything in the script works up until browser = webdriver.Firefox() - that is, the imports and display stuff all work fine. It's just that last line; for some reason, the browser doesn't want to open when a script tries to do it. This makes no sense and I'm really stumped. Possible reasons/fixes? Maybe something to do with permissions?

EDIT

Just to clarify, I'm doing this all on the remote server. By command line I'm using SSH with PUTTY, and when I try testing the script, I simply do it on the website.

  • 写回答

1条回答 默认 最新

  • douyun8885 2013-08-21 06:10
    关注

    Solved it by changing the permissions of the folder containing the Python script that called the webdriver from 755 to 757 (i.e., I gave write permissions to all users). I'm not sure whether this was a quirk of my situation because of something else I overlooked or whether there's actual insight to be gained here, but I'd say the take home lesson is if weird stuff is happening when working on an unfamiliar server, check the permissions.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试