溫馨提示×

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

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

python自動(dòng)化測(cè)試selenium核心技術(shù)等待條件有哪些

發(fā)布時(shí)間:2021-11-15 09:13:25 來源:億速云 閱讀:123 作者:小新 欄目:開發(fā)技術(shù)

這篇文章主要介紹python自動(dòng)化測(cè)試selenium核心技術(shù)等待條件有哪些,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!

Selenium中的鼠標(biāo)和鍵盤事件被封裝在ActionChains類中,使用方法:

ActionChains(driver).click(btn).perform()

ActionChains中常用方法:

python自動(dòng)化測(cè)試selenium核心技術(shù)等待條件有哪些

示例網(wǎng)站:http://sahitest.com/demo

示例場(chǎng)景:打開Sahi Tests頁面,點(diǎn)擊“Alert Test”頁面,鼠標(biāo)點(diǎn)擊頁面中“Click For Alert”按鈕,彈出警告提示框,判斷頁面是否存在alert,如存在則切換到警告框,并獲取警告文本信息,之后點(diǎn)警告框中的確定按鈕。

python自動(dòng)化測(cè)試selenium核心技術(shù)等待條件有哪些

python自動(dòng)化測(cè)試selenium核心技術(shù)等待條件有哪些

示例腳本:

from selenium import webdriver
from time import sleep
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec  
class TestWaitCondition(object):
    def setup(self):
        self.driver = webdriver.Chrome()
        self.driver.get("https://sahitest.com/demo/")
 
    def test_waitcondition(self):
        #點(diǎn)頁面上的Alert Test
        self.driver.find_element_by_xpath("/html/body/table/tbody/tr/td[3]/a[1]").click()
        #鼠標(biāo)點(diǎn)擊頁面中“Click For Alert”按鈕
        self.driver.find_element_by_name("b1").click()
 
        wait = WebDriverWait(self.driver,2)
        #等待并判斷警告框是否存在
        wait.until(ec.alert_is_present())
        #切換到alert頁面
        alert = self.driver.switch_to.alert
        #獲取并打印警告框中文本
        print(alert.text)
        #點(diǎn)彈出警告框中的確定
        alert.accept()
        self.driver.quit()

運(yùn)行結(jié)果:

python自動(dòng)化測(cè)試selenium核心技術(shù)等待條件有哪些

以上是“python自動(dòng)化測(cè)試selenium核心技術(shù)等待條件有哪些”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!

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

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

AI