w.switchTo().defaultContent();
String parwind = w.getWindowHandle();
Set<String> windows = w.getWindowHandles();
System.out.println(windows.size());
for(String handle : windows)
{
w.switchTo().window(handle);
System.out.println(handle);
}
String mainwind = w.getWindowHandle();
System.out.println(mainwind);
System.out.println(w.getTitle());
w.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);
w.switchTo().defaultContent();
w.switchTo().frame("menucontent");
w.findElement(By.xpath("//img[@id='toggleTreeExpand']")).click();
w.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
w.switchTo().frame(w.findElement(By.name("menuFr")));
w.findElement(By.xpath("//a[@title='RegisterAttend']")).click();
w.switchTo().defaultContent();
w.switchTo().frame("content");
w.switchTo().frame("commontoolbarFrame");
w.findElement(By.name("create")).click();
w.switchTo().defaultContent();
w.switchTo().frame("content");
w.switchTo().frame("f_query_add_mod");
w.switchTo().frame("query_sub");
w.findElement(By.name("first_name")).sendKeys("selenium");
w.findElement(By.xpath("//option[@value='M']")).click();
w.findElement(By.xpath("//input[@name='b_age']")).sendKeys("44");
w.switchTo().defaultContent();
w.switchTo().frame("content");
w.switchTo().frame("f_query_add_mod");
w.switchTo().frame("main");
w.findElement(By.xpath("//span[@id='findtl_tabspan']")).click();
w.switchTo().defaultContent();
Thread.sleep(5000);
Set<String> windows1 = w.getWindowHandles();
System.out.println(windows1.size());
for(String handles1 : windows1)
{
w.switchTo().window(handles1);
}
Thread.sleep(5000);
//w.switchTo().defaultContent();
w.switchTo().frame("MainFrame1");
w.findElement(By.name("blnggrpbut")).click();
w.switchTo().defaultContent();
Thread.sleep(5000);
Set<String> windows2 = w.getWindowHandles();
for(String handles2 : windows2)
{
w.switchTo().window(handles2);
}
Thread.sleep(5000);
System.out.println(windows2.size());
w.switchTo().defaultContent();
w.switchTo().frame("code_desc");
w.findElement(By.xpath("//a[@name='resulted_row']")).click();
w.switchTo().defaultContent();
Set<String> windows3 = w.getWindowHandles();
for(String handles3 : windows3)
{
w.switchTo().window(handles3);
System.out.println(w.getTitle());
}
w.switchTo().frame("MainFrame1");
w.findElement(By.name("close_button")).click();
w.switchTo().defaultContent();
w.switchTo().window(mainwind);
w.switchTo().frame("content");
w.switchTo().frame("commontoolbarFrame");
w.findElement(By.name("apply")).click();
w.switchTo().defaultContent();
Thread.sleep(5000);
Set<String> cancel = w.getWindowHandles();
for(String can : cancel)
{
w.switchTo().window(can);
}
w.switchTo().defaultContent();
錯誤:異常在線程「主」 org.openqa.selenium.NoSuchElementException:無法找到的xpath == //幀[@name元件='MainFrame1']硒未能識別隨機框架元件[2 5次]
如果我運行此代碼5次而不更改任何代碼,則其執行2次成功,其他3次失敗。
月1日試 - 通 第二次嘗試 - 失敗 第三嘗試 - 失敗 4RD嘗試 - 通過 第五嘗試 - 失敗
@ Mk08你可以給這個解決方案嗎? –