java selenium操作彈出對話框示例講解
Web 開發(fā)人員通常需要利用JavaScript彈出對話框來給用戶一些信息提示, 包括以下幾種類型
閱讀目錄
- 對話框類型
- 測試頁面
- Selenium 操作對話框的代碼
對話框類型
1. 警告框: 用于提示用戶相關(guān)信息的驗證結(jié)果, 錯誤或警告等
2. 提示框: 用于提示用戶在當前對話框中輸入數(shù)據(jù),一般需要用戶單擊取消或者確認按鈕
3. 確認框: 用于提示用戶確認或者取消某個操作,一般需要用戶單擊取消或者確認按鈕
測試頁面
用如下頁面為例進行講解, 包括了警告框,提示框,確認框
http://sislands.com/coin70/week1/dialogbox.htm
Selenium 操作對話框的代碼
public static void testAlert(WebDriver driver) { String url="http://sislands.com/coin70/week1/dialogbox.htm"; driver.get(url); WebElement alertButton = driver.findElement(By.xpath("http://input[@value='alert']")); alertButton.click(); Alert javascriptAlert = driver.switchTo().alert(); System.out.println(javascriptAlert.getText()); javascriptAlert.accept(); } public static void testPrompt(WebDriver driver) throws Exception { String url="http://sislands.com/coin70/week1/dialogbox.htm"; driver.get(url); WebElement promptButton = driver.findElement(By.xpath("http://input[@value='prompt']")); promptButton.click(); Thread.sleep(2000); Alert javascriptPrompt = driver.switchTo().alert(); javascriptPrompt.sendKeys("This is learning Selenium"); javascriptPrompt.accept(); System.out.println(javascriptPrompt.getText()); javascriptPrompt=driver.switchTo().alert(); javascriptPrompt.accept(); Thread.sleep(2000); promptButton.click(); javascriptPrompt=driver.switchTo().alert(); javascriptPrompt.dismiss(); Thread.sleep(2000); javascriptPrompt=driver.switchTo().alert(); javascriptPrompt.accept(); } public static void testConfirm(WebDriver driver) throws Exception { String url="http://sislands.com/coin70/week1/dialogbox.htm"; driver.get(url); WebElement confirmButton = driver.findElement(By.xpath("http://input[@value='confirm']")); confirmButton.click(); Thread.sleep(2000); Alert javascriptConfirm = driver.switchTo().alert(); javascriptConfirm.accept(); Thread.sleep(2000); javascriptConfirm = driver.switchTo().alert(); javascriptConfirm.accept(); }
以上就是對 java selenium操作彈出對話框的資料整理,后續(xù)繼續(xù)補充,謝謝大家對本站的支持!
相關(guān)文章
Spring Boot 實現(xiàn)https ssl免密登錄(X.509 pki登錄)
這篇文章主要介紹了Spring Boot 實現(xiàn)https ssl免密登錄(X.509 pki登錄),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-01-01基于spring cloud多個消費端重復(fù)定義feign client的問題
這篇文章主要介紹了spring cloud多個消費端重復(fù)定義feign client的問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-10-10springboot整合shiro實現(xiàn)登錄驗證授權(quán)的過程解析
這篇文章主要介紹了springboot整合shiro實現(xiàn)登錄驗證授權(quán),本文通過實例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-01-01