溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Selenium Client Driver for Python(1)

發(fā)布時(shí)間:2020-06-21 08:36:05 來源:網(wǎng)絡(luò) 閱讀:174 作者:ihaveadreamone 欄目:軟件技術(shù)

一、Introduction 簡介
介紹Selenium for Python.
1.selenium用于web自動(dòng)化測試。支持Python2.7, 3.4+以上版本。
二、selenium安裝
可以使用pip install -U selenium在線安裝,也可以下載源碼包,如selenium-3.13.0.tar.gz, 解壓后使用Python setup.py install進(jìn)行安裝。
三、驅(qū)動(dòng)安裝
selenium需要安裝驅(qū)動(dòng)以開啟關(guān)閉瀏覽器,如Firefox,需要geckodriver,把這個(gè)程序放到Firefox的安裝目錄下,并配置Firefox的環(huán)境變量。

四、實(shí)例
1.實(shí)例0:
(1)打開一個(gè)新的Firefox瀏覽器
(2)根據(jù)URL打開網(wǎng)頁
from selenium import webdriver

browser = webdriver.Firefox()
browser.get('http://seleniumhq.org')

2.實(shí)例1:
(1)打開一個(gè)新的Firefox瀏覽器
(2)加載雅虎主頁
(3)查找“seleniumhq”
(4)關(guān)閉瀏覽器

from selenium import webdriver
from selenium webdriver.common.keys import Keys

browser = webdriver.Firefox()

browser.get('http://www.yahoo.com')
assert 'Yahoo' in broeser.title

elem = browser.find_element_by_name('p')
elem.send_keys('seleniumhq' + Keys.RETURN)

browser.quit()

3.實(shí)例2:
selenium webdriver 也經(jīng)常用于web應(yīng)用程序基礎(chǔ)測試。

import unittest
from selenium import webdriver

class GoogleTestCase(unittest.TestCase):

def setUp(self):
    self.browser = webdriver.Firefox()
    self.addCleanup(self.browser.quit)

def testPageTitle(self):
    self.browser.get('http://www.google.com')
    self.assertIn('Google', self.browser.title)

if name == 'main':
unittest.main(verbosity=2)

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI