Mon script ne s'exécute pas correctement à chaque fois. Après l'exécution, il fonctionne parfois avec succès pendant 1 fois et la prochaine fois que je l'exécute à nouveau, il échoue. package Exemple;Mon script ne fonctionne pas correctement à chaque fois. Après l'exécution, il s'exécute parfois avec succès pendant 1 fois et la prochaine fois que je l'exécute à nouveau, il échoue
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();
}
}
S'il vous plaît aidez-moi sur ce problème dès que possible. Dans mon système, j'ai windows7, IE9. Mon application ne supporte mieux que dans IE. L'aide sera appréciée.
Quelle est l'erreur lorsque le script échoue? –
L'erreur se produisent à cet endroit. driver.findElement (By.xpath ("// * [@ id = 'BtnClose']")). click(); Le message d'erreur affiché est "log4j: WARN Aucun appender n'a pu être trouvé pour le logger (org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager) log4j: WARN Veuillez initialiser correctement le système log4j ID de la fenêtre principale: ac70653a-8834- 4843-bfde-16b229beed98 ID de la fenêtre principale: 28deebd4-025e-4eaa-8c66-e59e24e39332 Fenêtre principale ID: ac70653a-8834-4843-bfde-16b229beed98 Fenêtre contextuelle Titre: Désactiver l'alerte utilisateur désactivée en raison de InActivity –
ID de la fenêtre principale: 8b92c617 -8072-4b25-aa11-47fdc0b54477 Fenêtre pop-up Titre: 700Dealers Inc. Exception dans le thread "principal" org.openqa.selenium.NoSuchElementException: Impossible de trouver l'élément avec xpath == // * [@ id = 'BtnFermer '] (ATTENTION: le serveur n'a fourni aucune information de pile) Durée de la commande ou délai: 280 millisecondes Pour la documentation sur cette erreur, veuillez visiter: http: //seleniumhq.or g/exceptions/no_such_element.html Informations sur la version: version: '2.21.0', révision: '16552', heure: '2012-04-11 19: 08: 38'Informations système: os.name:' Windows 7 ' , os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_23' –