我的腳本每次都沒有成功運行。運行後有時會成功運行1次,下次運行時會失敗。 包示例;我的腳本每次都沒有成功運行。運行後,有時會成功運行1次,下次運行時會失敗
import java.io.FileInputStream;
import java.io.FileOutputStream;
import jxl.Sheet;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import java.util.Iterator;
import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class Script1
{
public static void main(String args[])throws Exception
{
//Take the data from input xls file
FileInputStream fi =new FileInputStream("D:\\selenium_test\\Object
Repositoty\\Input\\Login1.xls");
Workbook wb = Workbook.getWorkbook(fi);
Sheet sh = wb.getSheet(0);
//Create the Result xls file
FileOutputStream fo = new FileOutputStream("D:\\selenium_test\\Object
Repositoty\\Output\\Login_Results1.xls");
WritableWorkbook wwb = Workbook.createWorkbook(fo);
WritableSheet ws = wwb.createSheet("Results", 0);
Thread.sleep(20000);
String msg = "";
WebDriver driver = new InternetExplorerDriver();
driver.get("https://www.700creditsolution.com");
driver.manage().window().maximize();
Set<String> windowids = driver.getWindowHandles();
Iterator<String> iter= windowids.iterator();
for (int i = 1; i < sh.getRows(); i++)
{
while(iter.hasNext())
{
System.out.println("Main Window ID : "+iter.next());
}
driver.findElement(By.id("lgnLogin_UserName")).clear();
driver.findElement(By.id("lgnLogin_UserName")).sendKeys(sh.getCell(0,
i).getContents());
driver.findElement(By.id("lgnLogin_Password")).clear();
driver.findElement(By.id("lgnLogin_Password")).sendKeys(sh.getCell(1,
i).getContents());
driver.findElement(By.id("lgnLogin_LoginButton")).click();
Thread.sleep(5000L);
windowids = driver.getWindowHandles();
iter= windowids.iterator();
String main_windowID=iter.next();
String tabbed_windowID=iter.next();
System.out.println("Main Window ID :" +main_windowID);
Thread.sleep(2000);
//switch over to pop-up window
driver.switchTo().window(tabbed_windowID);
System.out.println("Pop-up window Title : "+driver.getTitle());
driver.findElement(By.xpath("//*[@id='BtnClose']")).click();
Thread.sleep(1000);
driver.switchTo().window(main_windowID);
msg= driver.findElement(By.xpath("//table[@id='lgnLogin']/tbody/tr/td/table
/tbody/tr[4]/td")).getText();
System.out.println(msg);
Thread.sleep(2000);
// driver.get("https://www.700creditsolution.com");
// Thread.sleep(2000);
for (int j = 0; j < sh.getColumns(); j++)
{
Label lab=new Label(j,i,sh.getCell(j, i).getContents());
ws.addCell(lab);
Label result = new Label(2,i, msg);
ws.addCell(result);
String c2String = sh.getCell(2, i).getContents().toString();
if(c2String.equalsIgnoreCase(msg))
{
Label status=new Label(3,i,"Pass");
ws.addCell(status);
}
else
{
Label status=new Label(3,i,"Fail");
ws.addCell(status);
}
}
}
Label un=new Label(0,0,"User ID");
Label pw=new Label(1,0,"Password");
Label rs=new Label(2,0,"Results");
Label st=new Label(3,0,"Status");
ws.addCell(un);
ws.addCell(pw);
ws.addCell(rs);
ws.addCell(st);
wwb.write();
wwb.close();
driver.quit();
}
}
請儘快幫我解決這個問題。在我的系統中,我有Windows7,IE9。我的應用程序只支持在IE中。幫助將不勝感激。
腳本失敗時的錯誤是什麼? –
錯誤在此位置得到。 。driver.findElement(By.xpath( 「// * [@ id中= 'BtnClose']」))點擊();顯示的錯誤信息是「log4j:WARN無法爲記錄器找到appender(org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager)。log4j:WARN請正確初始化log4j系統主窗口ID:ac70653a-8834- 4843-bfde-16b229beed98主窗口ID:28deebd4-025e-4eaa-8c66-e59e24e39332主窗口ID:ac70653a-8834-4843-bfde-16b229beed98彈出窗口標題:禁用由於InActivity而禁用用戶警報 –
主窗口ID:8b92c617 -8072-4b25-aa11-47fdc0b54477 彈出窗口標題:700Dealers Inc. 線程「main」中的異常org.openqa.selenium.NoSuchElementException:無法使用xpath查找元素== // * [@ id ='BtnClose ')(警告:服務器未提供任何堆棧跟蹤信息) 命令持續時間或超時:280毫秒 有關此錯誤的文檔,請訪問:http://seleniumhq.or g/exceptions/no_such_element.html 構建信息:版本:'2.21.0',修訂版本:'16552',時間:'2012-04-11 19:08:38'系統信息:os.name:'Windows 7' ,os.arch:'x86',os.version:'6.1',java.version:'1.6.0_23' –