Javascript 硒参数化错误处理
我已经为在SeleniumWeb驱动程序中登录有效和无效条目编写了参数化脚本。对于有效输入,脚本运行良好,但对于无效输入,脚本被卡住。现在,我想处理无效输入的错误,并想恢复脚本以进行下一次输入。那我该怎么做呢。请帮帮我 检查以下代码Javascript 硒参数化错误处理,javascript,Javascript,我已经为在SeleniumWeb驱动程序中登录有效和无效条目编写了参数化脚本。对于有效输入,脚本运行良好,但对于无效输入,脚本被卡住。现在,我想处理无效输入的错误,并想恢复脚本以进行下一次输入。那我该怎么做呢。请帮帮我 检查以下代码 public class Sample { public static void main(String[] args) throws InterruptedException, BiffException, IOException { //Logi
public class Sample {
public static void main(String[] args) throws InterruptedException, BiffException, IOException {
//Login Page
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
//Login parameterization using excel sheet (Jxl.jar)
Workbook wBook = Workbook.getWorkbook(new File("F:\\Selenium\\Parameterize\\login.xls"));
int i = 1;
//Get sheet
Sheet sheet = wBook.getSheet(0);
for(i = 1; i<sheet.getRows(); i++){
driver.get("https://www.Google.com");
//user name
driver.findElement(By.xpath("//*[@id='j_username']")).sendKeys(sheet.getCell(0, i).getContents());
//password
driver.findElement(By.xpath("//*[@id='j_password']")).sendKeys(sheet.getCell(1, i).getContents());
//submit
driver.findElement(By.xpath("//*[@id='signInForm']/div/div/div[7]/div[2]/button")).click();
Thread.sleep(5);
//TO move mouse to display Sign Out drop down window
Actions builder = new Actions(driver);
WebElement getElement = driver.findElement(By.xpath("//*[@id='welcomeSpanUserName']"));
builder.moveToElement(getElement).build().perform();
Thread.sleep(5);
//Click on Sign Out button
driver.findElement(By.xpath("//*[@id='wrapper']/div[2]/ul[2]/li[2]/ul/li[2]/span/a")).click();
}
}
}
公共类示例{
公共静态void main(字符串[]args)抛出InterruptedException、BiffeException、IOException{
//登录页面
WebDriver=newfirefoxdriver();
driver.manage().window().maximize();
//使用excel工作表(Jxl.jar)进行登录参数化
工作簿wBook=Workbook.getWorkbook(新文件(“F:\\Selenium\\Parameterize\\login.xls”);
int i=1;
//拿床单
Sheet Sheet=wBook.getSheet(0);
对于(i=1;i请尝试在循环中使用Try..catch块,如果出现异常,将继续下一次迭代
public class Sample {
public static void main(String[] args) throws InterruptedException, BiffException, IOException {
//Login Page
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
//Login parameterization using excel sheet (Jxl.jar)
Workbook wBook = Workbook.getWorkbook(new File("F:\\Selenium\\Parameterize\\login.xls"));
int i = 1;
//Get sheet
Sheet sheet = wBook.getSheet(0);
for(i = 1; i<sheet.getRows(); i++){
try{
driver.get("https://115.112.36.94:7443/");
//user name
driver.findElement(By.xpath("//*[@id='j_username']")).sendKeys(sheet.getCell(0, i).getContents());
//password
driver.findElement(By.xpath("//*[@id='j_password']")).sendKeys(sheet.getCell(1, i).getContents());
//submit
driver.findElement(By.xpath("//*[@id='signInForm']/div/div/div[7]/div[2]/button")).click();
Thread.sleep(5);
//TO move mouse to display Sign Out drop down window
Actions builder = new Actions(driver);
WebElement getElement = driver.findElement(By.xpath("//*[@id='welcomeSpanUserName']"));
builder.moveToElement(getElement).build().perform();
Thread.sleep(5);
//Click on Sign Out button
driver.findElement(By.xpath("//*[@id='wrapper']/div[2]/ul[2]/li[2]/ul/li[2]/span/a")).click();
}catch(Exception e){
//handle exception if you need
}
}
}
}
公共类示例{
公共静态void main(字符串[]args)抛出InterruptedException、BiffeException、IOException{
//登录页面
WebDriver=newfirefoxdriver();
driver.manage().window().maximize();
//使用excel工作表(Jxl.jar)进行登录参数化
工作簿wBook=Workbook.getWorkbook(新文件(“F:\\Selenium\\Parameterize\\login.xls”);
int i=1;
//拿床单
Sheet Sheet=wBook.getSheet(0);
for(i=1;iExplore java中的异常处理并使用它……)