Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1363402
  • 博文数量: 244
  • 博客积分: 3321
  • 博客等级: 中校
  • 技术积分: 2704
  • 用 户 组: 普通用户
  • 注册时间: 2009-04-26 08:17
个人简介

微信公众号:杰夫弹弹看

文章分类

全部博文(244)

文章存档

2018年(4)

2017年(32)

2016年(25)

2015年(28)

2014年(27)

2013年(34)

2012年(25)

2011年(30)

2010年(39)

分类: Python/Ruby

2016-08-14 10:13:30

关于ubuntu的介绍如下:



1. 如果使用的是yum源系统,安装如下的包:

yum install xorg-x11-server-Xvfb.x86_64

2. 然后执行如下,启动xvfb服务:

Xvfb :10 -ac


3. 在系统中以headless方式启动centos
export DISPLAY=:10
firefox

4.  执行selenium测试:
python code 如下:

```
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0

# Create a new instance of the Firefox driver
driver = webdriver.Firefox()

# go to the baidu home page
driver.get("")

# the page is ajaxy so the title is originally this:
print driver.title

# find the element that's name attribute is q (the baidu search box)
inputElement = driver.find_element_by_name("wd")

# type in the search
inputElement.send_keys("cheese!")

# submit the form (although baidu automatically searches now without submitting)
inputElement.submit()

try:
    # we have to wait for the page to refresh, the last thing that seems to be updated is the title
    WebDriverWait(driver, 10).until(EC.title_contains("cheese!"))

    # You should see "cheese! - baidu Search"
    print driver.title

finally:
        driver.quit()

```

运行如下:
百度一下,你就知道
cheese!_百度搜索
阅读(705) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~