Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Se (11)-Alert

Shulou Source: shulou.com Published: 2022-06-03 05:03:50 10月01日 Update

Package testWd

Import org.openqa.selenium.Alert

Import org.openqa.selenium.By

Import org.openqa.selenium.WebDriver

Import org.openqa.selenium.WebElement

Import org.openqa.selenium.chrome.ChromeDriver

Import org.testng.annotations.Test

Public class findEle {

@ Test

Public void findElement () throws InterruptedException {

System.setProperty ("webdriver.chrome.driver", "DJV 01 Learn WebDriver/chromedriver.exe")

WebDriver dr = new ChromeDriver ()

Dr.manage (). Window (). Maximize ()

/ / Alert

/ * dr.get ("http://www.w3school.com.cn/tiy/t.asp?f=hdom_alert");"

WebElement el = dr.findElement (By.xpath ("/ / * [@ name='i']"))

Dr.switchTo () .frame ("I")

WebElement el1 = dr.findElement (By.xpath ("/ / input"))

El1.click ()

Alert alert1 = dr.switchTo () .alert ()

System.out.println (alert1.getText ())

Thread.sleep (5000)

Alert1.accept (); * /

/ / confirm

/ * dr.get ("http://www.w3school.com.cn/tiy/t.asp?f=hdom_confirm");"

WebElement el = dr.findElement (By.xpath ("/ / * [@ name='i']"))

Dr.switchTo () .frame ("I")

WebElement el1 = dr.findElement (By.xpath ("/ / input"))

El1.click ()

Alert confirm1 = dr.switchTo () .alert ()

Thread.sleep (2000)

System.out.println (confirm1.getText ())

Confirm1.accept ()

Thread.sleep (2000)

Confirm1 = dr.switchTo () .alert ()

Thread.sleep (2000)

System.out.println (confirm1.getText ())

Confirm1.accept ()

El1.click ()

Confirm1 = dr.switchTo () .alert ()

Thread.sleep (2000)

System.out.println (confirm1.getText ())

Confirm1.dismiss ()

Thread.sleep (2000)

Confirm1 = dr.switchTo () .alert ()

System.out.println (confirm1.getText ())

Confirm1.accept (); * /

/ / Prompt

Dr.get ("http://www.w3school.com.cn/tiy/t.asp?f=hdom_prompt");"

WebElement el = dr.findElement (By.xpath ("/ / * [@ name='i']"))

Dr.switchTo () frame (el)

WebElement el1 = dr.findElement (By.xpath ("/ / input"))

El1.click ()

Alert prompt1 = dr.switchTo () .alert ()

Thread.sleep (2000)

System.out.println (prompt1.getText ())

Prompt1.dismiss ()

WebElement el2 = dr.findElement (By.xpath ("/ html/body"))

System.out.println (el2.getText ())

Thread.sleep (2000)

El1.click ()

Prompt1 = dr.switchTo () .alert ()

Thread.sleep (2000)

System.out.println (prompt1.getText ())

Prompt1.sendKeys ("Jerry")

Prompt1.accept ()

El2 = dr.findElement (By.xpath ("/ html/body"))

System.out.println (el2.getText ())

/ / Thread.sleep (3000)

/ / dr.quit ()

}

}

Tags: Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Huawei Microsoft macOS NVidia