...14 for(int i = 0; i<Integer.parseInt(Environment.get("Selenium.waittime")); i++){15 try{16 driver.switchTo().frame(id);17 return;18 }catch(org.openqa.selenium.NoSuchFrameException e){19 Logger.getLogger(SwitchTo.class.getName()).log(Level.INFO, "driver.switchTo().frame("+ id +") not found:. time :" + i);20 } 21 try {22 Thread.sleep(1000);23 } catch (InterruptedException ex) {24 Logger.getLogger(SwitchTo.class.getName()).log(Level.SEVERE, null, ex);25 }26 }27 throw new org.openqa.selenium.NoSuchFrameException("driver.switchTo().frame("+ id +")");28 } 29 30 //éå¼çå¾
frameåºç°ãéè¿nameå®ä½frame31 public static void frame(WebDriver driver,String name){32 for(int i = 0; i<Integer.parseInt(Environment.get("Selenium.waittime")); i++){33 try{34 driver.switchTo().frame(name);35 return;36 }catch(org.openqa.selenium.NoSuchFrameException e){37 Logger.getLogger(SwitchTo.class.getName()).log(Level.INFO, "driver.switchTo().frame("+ name +") not found:. time :" + i);38 } 39 try {40 Thread.sleep(1000);41 } catch (InterruptedException ex) {42 Logger.getLogger(SwitchTo.class.getName()).log(Level.SEVERE, null, ex);43 }44 }45 throw new org.openqa.selenium.NoSuchFrameException("driver.switchTo().frame("+ name +")");46 } 47 48 //éè¿windowsçtitleå®æswitchå°windows49 public static void window(WebDriver driver,String title){50 for(int i = 0; i<Integer.parseInt(Environment.get("Selenium.waittime")); i++){51 for (String handle : driver.getWindowHandles()) {52 driver.switchTo().window(handle);53 if(driver.getTitle().equals(title)){54 return ;55 }56 }57 Logger.getLogger(SwitchTo.class.getName()).log(Level.INFO, "SwitchTo.window("+ title +"). No windows have the title :" + title+"- failed -time:" + i );58 try {59 Thread.sleep(1000);60 } catch (InterruptedException ex) {61 Logger.getLogger(SwitchTo.class.getName()).log(Level.SEVERE, null, ex);62 }63 }64 throw new org.openqa.selenium.NoSuchFrameException("SwitchTo.window("+ title +"). No windows have the title :" + title); 65 } 66 67 /*68 * å®ä½å°å
å«å
·ä½elementçwindows69 */70 public static void window(WebDriver driver,By locater){71 72 //driver.switchTo().window("");73 74 for(int i = 0; i<Integer.parseInt(Environment.get("Selenium.waittime")); i++){75 for (String handle : driver.getWindowHandles()) {76 driver.switchTo().window(handle);77 if(Check.checkElementExist(driver, locater,0)){78 return ;79 }80 }81 Logger.getLogger(SwitchTo.class.getName()).log(Level.INFO, "could not find the window that have the element :" + locater.toString()+" -time:" + i );82 try {83 Thread.sleep(1000);84 } catch (InterruptedException ex) {85 Logger.getLogger(SwitchTo.class.getName()).log(Level.SEVERE, null, ex);86 } 87 }88 throw new org.openqa.selenium.NoSuchFrameException("could not find the window that have the element :" + locater.toString() ); 89 } 90 /*91 * å®ä½å°å
å«bodyä¸å
·ä½å符串ççwindows92 */93 public static void windowWithContent(WebDriver driver,String bodycontent){94 for(int i = 0; i<Integer.parseInt(Environment.get("Selenium.waittime")); i++){95 for (String handle : driver.getWindowHandles()) {96 driver.switchTo().window(handle);97 if(StringUtils.contains(driver.findElement(By.tagName("body")).getText(), bodycontent)){98 return;99 }100 }101 102 Logger.getLogger(SwitchTo.class.getName()).log(Level.INFO, "could not find the window thatbody have string:" + bodycontent+" -time:" + i );103 try {104 Thread.sleep(1000);105 } catch (InterruptedException ex) {106 Logger.getLogger(SwitchTo.class.getName()).log(Level.SEVERE, null, ex);107 } 108 }109 throw new org.openqa.selenium.NoSuchFrameException("could not find the window thatbody have string:" + bodycontent ); 110 } 111 /*112 * å®ä½ä¸ºæå®urlçwindows113 */114 public static void windowWithUrl(WebDriver driver,String url){115 for(int i = 0; i<Integer.parseInt(Environment.get("Selenium.waittime")); i++){116 for (String handle : driver.getWindowHandles()) {117 driver.switchTo().window(handle);118 if(driver.getCurrentUrl().equalsIgnoreCase(url)){119 return;120 }121 }122 123 Logger.getLogger(SwitchTo.class.getName()).log(Level.INFO, "could not find the window that url is:" + url+" -time:" + i );124 try {125 Thread.sleep(1000);126 } catch (InterruptedException ex) {127 Logger.getLogger(SwitchTo.class.getName()).log(Level.SEVERE, null, ex);128 } 129 }130 throw new org.openqa.selenium.NoSuchFrameException("could not find the window that url is:" + url); 131 } 132}...