Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Se (11)-Alert

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

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 ()

}

}

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report