您好,登錄后才能下訂單哦!
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", "D:/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("http://*[@name='i']"));
dr.switchTo().frame("i");
WebElement el1 = dr.findElement(By.xpath("http://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("http://*[@name='i']"));
dr.switchTo().frame("i");
WebElement el1 = dr.findElement(By.xpath("http://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("http://*[@name='i']"));
dr.switchTo().frame(el);
WebElement el1 = dr.findElement(By.xpath("http://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();
}
}
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。