?????????????????Щ??????
???????????? ???????[ 2013/9/9 14:47:28 ] ????????
????1??WebDriver?????Щ????
import java.util.Set;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.NoAlertPresentException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class AlertOperate {
static WebDriver dr = new InternetExplorerDriver();
public static void main(String args[]) throws InterruptedException{
dr.get("www.baidu.com");
dr.findElement(By.id("lb")).click();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
tanchukuang();
}
//????????1??alert??javascript??????
public boolean dealPotentialAlert(WebDriver driver??boolean option) {
boolean flag = false;
try {
Alert alert = driver.switchTo().alert();
if (null == alert)
throw new NoAlertPresentException();
try {
if (option) {
alert.accept();
System.out.println("Accept the alert: " + alert.getText());
} else {
alert.dismiss();
System.out.println("Dismiss the alert: " + alert.getText());
}
flag = true;
} catch (WebDriverException ex) {
if (ex.getMessage().startsWith("Could not find"))
System.out.println("There is no alert appear!");
else
throw ex;
}
} catch (NoAlertPresentException e) {
System.out.println("There is no alert appear!");
}
return flag;
}
//?????JS????
public static boolean testNewWindow(){
//?????????
String currentHandle = dr.getWindowHandle();
//??????д??????
Set<String> handles = dr.getWindowHandles();
handles.remove(currentHandle);
if (handles.size() > 0) {
try{
dr.switchTo().window(handles.iterator().next());
//dr.switchTo().window(dr.getWindowHandles().iterator().next());
return true;
}catch(Exception e){
System.out.println(e.getMessage());
return false;
}
}
System.out.println("Did not find window");
return false;
}
//?????????
public static void tanchukuang() throws InterruptedException{
//??????д???
Set<String> allWindowsId = dr.getWindowHandles();
//?????????????????μ????
for(String windowId : allWindowsId){
dr.switchTo().window(windowId);
Thread.sleep(1000);
dr.findElement(By.id("TANGRAM__PSP_10__userName")).sendKeys("test");
//????????????????
//dr.findElement(By.xpath("//button[@type='button']")).click();
//System.out.println(dr.switchTo().window(windowId).getTitle());
break;
}
}
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11