欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時(shí)間:2021年11月13日 11:26:51   作者:aovenus  
這篇文章主要為大家介紹了python自動(dòng)化測(cè)試selenium核心技術(shù)等待條件教程的示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助

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

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

ActionChains中常用方法:

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

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

示例腳本:

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é)果:

以上:來自極客時(shí)間課程:selenium自動(dòng)化測(cè)試學(xué)習(xí)總結(jié)。

以上就是python自動(dòng)化測(cè)試selenium核心技術(shù)等待條件教程的詳細(xì)內(nèi)容,更多關(guān)于selenium等待條件教的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評(píng)論