日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Selenium对于对话框alert,confirm,prompt的处理

發布時間:2024/4/15 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Selenium对于对话框alert,confirm,prompt的处理 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

html 源碼:


??? <html> ?
???? ?
??????? <head> ?
???? ?
??????????? <title>Alert</title> ?
<script>
function myFunction()
?{
?? ?var x;
?? ?var b = prompt("hello","harry potter");
??? if (b!=null && b!="") {
?? ?
?? ?x = "hello"+b+"歡迎你";
?? ?
??? ?}
?? ?document.getElementById("display").innerHTML=x;
?}

</script>

????
??????? </head> ?
???? ?
??????? <body> ?
???? ?
?????? ??? ?<input id = "alert" value = "alert" type = "button" onclick = "alert('歡迎!請按確認繼續!');"/> ?
?????? ??? ?<input id = "confirm" value = "confirm" type = "button" onclick = "confirm('確定嗎?');"/> ?
?????? ??? ?<input id = "prompt" value = "prompt" type = "button" onclick = "myFunction()" /> ?
?? ? ? ?? ? <p id = "display"></p>
???????? ?
???? ?
??????? </body> ?
???? ?
??? </html>?


?以上html代碼在頁面上顯示了三個按鈕,點擊他們分別彈出alert、confirm、prompt對話框。如果在prompt對話框中輸入文字點擊確定之后,將會刷新頁面,顯示出這些文字


  • import?org.openqa.selenium.Alert;??
  • import?org.openqa.selenium.By;??
  • import?org.openqa.selenium.WebDriver;??
  • import?org.openqa.selenium.firefox.FirefoxDriver;??
  • ??
  • public?class?DialogsStudy?{??
  • ??
  • ????/**?
  • ?????*?@wuyepiaoxue
  • ?????*/??
  • ????public?static?void?main(String[]?args)?{??
  • ????????//?TODO?Auto-generated?method?stub??
  • ????????System.setProperty("webdriver.firefox.bin","D:/Program Files (x86)/Mozilla Firefox/firefox.exe");????
  • ????????WebDriver?dr?=?new?FirefoxDriver();??
  • ????????String?url?=?"file:///C:/Users/Administrator/Desktop/test.htm";
  • ????????dr.get(url);??
  • ??????????
  • ????????//點擊第一個按鈕,輸出對話框上面的文字,然后叉掉??
  • ????????dr.findElement(By.id("alert")).click();??
  • ????????Alert?alert?=?dr.switchTo().alert();??
  • ????????String?text?=?alert.getText();??
  • ????????System.out.println(text);??
  • ????????alert.dismiss();??
  • ??????????
  • ????????//點擊第二個按鈕,輸出對話框上面的文字,然后點擊確認??
  • ????????dr.findElement(By.id("confirm")).click();??
  • ????????Alert?confirm?=?dr.switchTo().alert();??
  • ????????String?text1?=?confirm.getText();??
  • ????????System.out.println(text1);??
  • ????????confirm.accept();??
  • ??????????
  • ????????//點擊第三個按鈕,輸入你的名字,然后點擊確認,最后??
  • ????????dr.findElement(By.id("prompt")).click();??
  • ????????Alert?prompt?=?dr.switchTo().alert();??
  • ????????String?text2?=?prompt.getText();??
  • ????????System.out.println(text2);??
  • ????????prompt.sendKeys("jarvi");??
  • ????????prompt.accept();??
  • ??????????
  • ????}??
  • ??
  • }?
  • 轉載于:https://www.cnblogs.com/wuyepiaoxue/p/5661187.html

    總結

    以上是生活随笔為你收集整理的Selenium对于对话框alert,confirm,prompt的处理的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。