2015-06-05 54 views
0
   WebElement user = driver1.findElement(By.id("usrname")); 
user.sendKeys("username"); 
System.out.println("Username entered"); 

WebElement password = driver1.findElement(By.id("usrpwd")); 
password.sendKeys("password"); 
System.out.println("password entered"); 

WebElement submit = driver1.findElement(By.xpath(".//*[@id='ibm-pcon']/form/table[2]/tbody/tr/td/input[1]")); 
submit.click(); 
System.out.println("submit button entered"); 

Thread.sleep(7000); 

WebElement role = driver1.findElement(By.xpath("//input[@id='userRole'][@value='ARCOL '][@type='radio'][@name='role']")); 
role.click(); 
System.out.println("role entered");  

It is not able to find the element in web page by.xpath. Till thread.sleep() method code is running fine, but after that it is throwing error. Error: Exception in thread "main" org.openqa.selenium.NoSuchWindowException: Unable to find element on closed window (WARNING: The server did not provide any stacktrace information)为什么这个硒脚本(在IE11上)不能在Thread.sleep(7000)之后工作;

回答

0
driver1.findElement(By.xpath(".//*[@id='ibm-pcon']/form/table[2]/tbody/tr/td/input[1]")) 

后您点击元素,有可能是网页的iframe /弹出。

尝试经由

driver.switchTo().defaultContent(); // default frame 
driver.switchTo().frame(YOURCURRENTFRAME); 
+0

在这里,我们没有使用任何iframe,并为记录和回放它工作正常。但是通过这个手册代码,它无法在网页中找到元素 –

0
  1. 尝试帧之间切换使用ExplicitWait代替了Thread.sleep();
  2. 检查driver1.getWindowHandle(); submit.click();之前和之后他们应该是一样的。
相关问题