参考:http://www.cnblogs.com/fnng/archive/2013/05/29/3106515.html

ubuntu 安装过程:

1、安装:setuptools

$ apt-get install python-setuptools

2、安装pip

1)源码安装方式(cd进python目录下)如下:

$ tar -zxvf pip-1.4.1.tar.gz

$ cd pip-1.4.1/

$ python setup.py install

2)这里直接使用apt-get安装:

$sudo apt-get install python-pip

参考:http://www.pip-installer.org/en/latest/installing.html

  注意,通过查看pip官网,V1.5.1以上版本,可以不安装python-setuptools

  安装后,可通过pip --version查看一下已安装的版本及安装路径。

3、安装selenium

进入pip安装目录下(如/usr/lib/python2.7/dist-packages/pip),执行下列语句:

$sudo pip install -U selenium

当出现
Successfully installed selenium
Cleaning up...

时说明安装成功。

4、验证selenium是否安装成功。

在ubuntu下,新建一个脚本pytest.py,脚本如下:

from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
import time browser = webdriver.Firefox() # Get local session of firefox
browser.get("http://www.yahoo.com") # Load page
assert "Yahoo!" in browser.title
elem = browser.find_element_by_name("p") # Find the query box
elem.send_keys("seleniumhq" + Keys.RETURN)
time.sleep(0.2) # Let the page load, will be added to the API
try:
browser.find_element_by_xpath("//a[contains(@href,'http://seleniumhq.org')]")
except NoSuchElementException:
assert 0, "can't find seleniumhq"
browser.close()

如果是上述脚本,则在终端下使用python /pytest.py 命令执行。

若在脚本最开始前存在

#!/usr/bin/env python

则可以像sh文件一样执行。好像还需要对python设置成环境变量才成。

$ ./pytest.py

遇到的问题1:

python /pytest.py命令执行后,提示“IndentationError: unexpected unindent”

分析原因:脚本第一行未与其他行对齐。

遇到的问题2:

修改将代码对齐后,再次执行,又出现问题。如下所示:

Traceback (most recent call last):
File "/testyjw/pytest.py", line 7, in <module>
browser = webdriver.Firefox() # Get local session of firefox
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 59, in __init__
self.binary, timeout),
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/extension_connection.py", line 47, in __init__
self.binary.launch_browser(self.profile)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 61, in launch_browser
self._wait_until_connectable()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 100, in _wait_until_connectable
self._get_firefox_output())
selenium.common.exceptions.WebDriverException: Message: "The browser appears to have exited before we could connect. The output was: \n(process:14510): GLib-CRITICAL **: g_slice_set_config: assertion `sys_page_size == 0' failed\nError: no display specified\n"

分析原因:

windows下使用ssh终端远程连接ubuntu,运行脚本存在上面问题。而直接在ubuntu上操作执行,则不存在问题。有待进一步分析。

ubuntu下安装selenium2.0 环境的更多相关文章

  1. Fedora和Ubuntu下安装OpenGL开发环境配置

    Fedora下OpenGl开发环境配置 开发OpenGL工程需要3个库文件和对应的头文件: libglut.so,libGLU.so,libGL.so, gl.h ,glu.h, glut.h 这些库 ...

  2. ubuntu下安装stm32开发环境

    在windowns下开发stm32刚开始学最烦的就是创建工程模板,都不知道为什么要那样设置,而且步骤繁多.现在我告诉大家一个好消息,在linux下配置stm32开发环境包括创建工程,使用JLink仿真 ...

  3. Ubuntu下安装CUDA8.0及nvidia驱动

    参考:https://blog.csdn.net/qq_35379989/article/details/80147630 cuda的历史版本下载地址:https://developer.nvidia ...

  4. ubuntu下安装MySQL8.0

    为了一劳永逸不每次都到处找资料,花了一下午时间做了这些.其中大部分是根据官方手册来的,后面部分谢谢大佬的帮助,超开心. 一.首先,将MySQL APT存储库添加到系统的软件存储库列表中 1.转到htt ...

  5. ubuntu下安装ESP8266开发环境步骤中可能出现的问题及解决办法

    安装步骤参考如下链接 https://www.jianshu.com/p/e9ce2a60df83 1.在GitHub上拉取代码时发生错误:RPC failed; curl 18 transfer c ...

  6. ubuntu下安装cpython 0.2x

    Quick installation of cython: Step 1: Update system: sudo apt-get update Step 2: Install: cython Ate ...

  7. 在Windows/Ubuntu下安装OpenGL环境(GLUT/freeglut)与跨平台编译(mingw/g++)

    GLUT/freeglut 是什么? OpenGL 和它们有什么关系? OpenGL只是一个标准,它的实现一般自带在操作系统里,只要确保显卡驱动足够新就可以使用.如果需要在程序里直接使用OpenGL, ...

  8. CAFFE(一):Ubuntu 下安装CUDA(安装:NVIDIA-384+CUDA9.0+cuDNN7.1)

    (安装:NVIDIA-384+CUDA9.0+cuDNN7.1) 显卡(GPU)驱动:NVIDIA-384 CUDA:CUDA9.0 cuDNN:cuDNN7.1 Ubuntu 下安装CUDA需要装N ...

  9. anaconda环境中---py2.7下安装tf1.0 + py3.5下安装tf1.5

    anaconda环境中---py2.7下安装tf1.0 + py3.5下安装tf1.5 @wp20181030 环境:ubuntu18.04, anaconda2, ubuntu系统下事先安装了pyt ...

随机推荐

  1. POJ1573Robot Motion

    http://poj.org/problem?id=1573 #include<stdio.h> #include<stdlib.h> #include<cstring& ...

  2. 架构探险——从零开始写Java Web框架》第二章照作

    沉下来慢慢看实现了. 越来越觉得可以和DJANGO作对比. package org.smart4j.chapter2.model; /** * Created by sahara on 2016/3/ ...

  3. hdu 4038 Stone

    思路: 如果负数的个数为偶数则不必改变,为奇数就将最大负数变为正: 对于正数,尽量将1,2变为3即可. 代码如下: #include<cstring> #include<iostre ...

  4. hdu 3923 Invoker

    完全是套用polya模版…… ;}

  5. VCL ActiveX 播放视频

    播放网络视频 string[] options = new string[] { ":sout=#duplicate{dst=display} :no-overlay" }; st ...

  6. ssm框架整合小结

    1.整合思路 一.Dao层:整合mybatis和spring 需要的jar包: 1.mybatis的jar包 2.Mysql数据库驱动 3.数据库连接池 4.Mybatis和spring的整合包. 5 ...

  7. CentOS7 升级python同时解决yum损坏问题

    CentOS7中的python版本为python2.7.5,升级到最新版的python时需要注意两个问题 新版的python安装好后要修改python的系统默认指向问题 升级到最新版python后yu ...

  8. 写出优秀论文How To Write A Great Essay About Anything

    There is an assumption in the world that an essay is something literary you write for school about a ...

  9. NDK(22)JNI编程如何避免常见缺陷

    转自 : http://www.ibm.com/developerworks/cn/java/j-jni/index.html 避免常见缺陷 假设您编写了一些新 JNI 代码,或者继承了别处的某些 J ...

  10. CentOS 6.5系统使用yum方式安装LAMP环境和phpMyAdmin详细过程

    介绍如何在CentOs6.2下面使用YUM配置安装LAMP环境,一些兄弟也很喜欢使用编译的安装方法,个人觉得如果不是对服务器做定制,用yum安装稳定简单,何必去download&make&am ...