您的位置:首页 > 其它

Selenium 安装和测试

2017-08-21 11:00 204 查看
>>>pip install -Uselenium
 
对于Chrome,
1)
下载Chrome drive:(是个独立的exe)
https://sites.google.com/a/chromium.org/chromedriver/home
 
参考文档做设置:
https://sites.google.com/a/chromium.org/chromedriver/getting-started
 
测试代码:
 
fromselenium import webdriver
fromselenium.common.exceptions import NoSuchElementException
fromselenium.webdriver.common.keys import Keys
importtime
 
browser =webdriver.Chrome('C:/Program Files (x86)/chromedriver.exe')  # Optional argument, if not specified willsearch path.
browser.get("http://www.yahoo.com")# Load page
assert"Yahoo!" in browser.title
elem =browser.find_element_by_name("p1") # 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')]")
exceptNoSuchElementException:
    assert 0, "can't find seleniumhq"
browser.close()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: