ubuntu下安装selenium2.0 环境
参考: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 环境的更多相关文章
- Fedora和Ubuntu下安装OpenGL开发环境配置
Fedora下OpenGl开发环境配置 开发OpenGL工程需要3个库文件和对应的头文件: libglut.so,libGLU.so,libGL.so, gl.h ,glu.h, glut.h 这些库 ...
- ubuntu下安装stm32开发环境
在windowns下开发stm32刚开始学最烦的就是创建工程模板,都不知道为什么要那样设置,而且步骤繁多.现在我告诉大家一个好消息,在linux下配置stm32开发环境包括创建工程,使用JLink仿真 ...
- Ubuntu下安装CUDA8.0及nvidia驱动
参考:https://blog.csdn.net/qq_35379989/article/details/80147630 cuda的历史版本下载地址:https://developer.nvidia ...
- ubuntu下安装MySQL8.0
为了一劳永逸不每次都到处找资料,花了一下午时间做了这些.其中大部分是根据官方手册来的,后面部分谢谢大佬的帮助,超开心. 一.首先,将MySQL APT存储库添加到系统的软件存储库列表中 1.转到htt ...
- ubuntu下安装ESP8266开发环境步骤中可能出现的问题及解决办法
安装步骤参考如下链接 https://www.jianshu.com/p/e9ce2a60df83 1.在GitHub上拉取代码时发生错误:RPC failed; curl 18 transfer c ...
- ubuntu下安装cpython 0.2x
Quick installation of cython: Step 1: Update system: sudo apt-get update Step 2: Install: cython Ate ...
- 在Windows/Ubuntu下安装OpenGL环境(GLUT/freeglut)与跨平台编译(mingw/g++)
GLUT/freeglut 是什么? OpenGL 和它们有什么关系? OpenGL只是一个标准,它的实现一般自带在操作系统里,只要确保显卡驱动足够新就可以使用.如果需要在程序里直接使用OpenGL, ...
- 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 ...
- anaconda环境中---py2.7下安装tf1.0 + py3.5下安装tf1.5
anaconda环境中---py2.7下安装tf1.0 + py3.5下安装tf1.5 @wp20181030 环境:ubuntu18.04, anaconda2, ubuntu系统下事先安装了pyt ...
随机推荐
- .net中的认证(authentication)与授权(authorization)
“认证”与“授权”是几乎所有系统中都会涉及的概念,通俗点讲: 1.认证(authentication) 就是 "判断用户有没有登录?",好比windows系统,没登录就无法使用(不 ...
- java基础知识回顾之---java String final类 容易混淆的java String常量池内存分析
/** * 栈(Stack) :存放基本类型的变量数据和对象的引用,但对象本身不存放在栈中,而是存放在堆(new 出来的对象)或者常量池中(字符串常量对象存放 在常量池中). 堆(heap):存 ...
- *[topcoder]TaroFriends
http://community.topcoder.com/stat?c=problem_statement&pm=13005 好题.最暴力是试验2^n种跳法.然后有从结果入手,那么最终的左右 ...
- Java学习笔记之:Java 继承
一.引言 继承是java面向对象编程技术的一块基石,因为它允许创建分等级层次的类.继承可以理解为一个对象从另一个对象获取属性的过程. 如果类A是类B的父类,而类B是类C的父类,我们也称C是A的子类,类 ...
- IP地址字符串与BigInteger的转换
/** * Copyright (c) 2010, 新浪网支付中心 * All rights reserved. * * Java IP地址字符串与BigInteger的转换, * ...
- HDU5088——Revenge of Nim II(高斯消元&矩阵的秩)(BestCoder Round #16)
Revenge of Nim II Problem DescriptionNim is a mathematical game of strategy in which two players tak ...
- opengl 杂记
函数原型: void glClear(GLbitfield mask); 参数说明: GLbitfield:可以使用 | 运算符组合不同的缓冲标志位,表明需要清除的缓冲,例如glClear(GL_CO ...
- 转载:C++ STL set学习
声明:本文转载自Penguin的博客 http://blog.sina.com.cn/s/blog_779cf3410101389s.html 1,set的含义是集合,它是一个有序的容器,里面的元素都 ...
- perl基本语法
标量 标量是 Perl 中最简单的数据类型.大多数的标量是数字(如 255 或 3.25e20)或者字符串(如 hello或者盖茨堡地址). 数字 perl中所有数字内部的格式都是双精度浮点数. 浮点 ...
- HDU 1754 I Hate It (线段树 单点更新)
题目链接 中文题意,与上题类似. #include <iostream> #include <cstdio> #include <cstring> #include ...