selenium依次点击页面的删除按钮

需要依次点击页面的删除按钮,如下图:

 

	@Test
	public static void FaBu() {
		
		TestMenuJump.jumpExam(driver);

		 TestMenuJump.jumpExamPa(driver);
				
		WebElement wes = driver.findElement(By.id("Category"));
		Select sc = new Select(wes);
		sc.selectByIndex(3);
		wes.submit();
		
		//driver.findElement(By.id("Content")).sendKeys(""+i);		
		//driver.findElement(By.className("btn btn-info btn-sm"));
		WebElement we = driver.findElement(By.linkText("下一页"));
		do{			
			List<WebElement> list = driver.findElements(By.linkText("删除"));
			if(list.size()>0) {
				for(int i=0;i<list.size();i++) {
					driver.findElement(By.linkText("删除")).click();
					Alert alert = driver.switchTo().alert();
					alert.dismiss();
					
				}
			}
			System.out.println(list.size());
			/*for(WebElement we1:list) {
				we1.click();
				Alert alert = driver.switchTo().alert();
				alert.dismiss();
			}*/
			try{
				WebElement wel = driver.findElement(By.linkText("下一页"));
				wel.click();
			}catch(NoSuchElementException e){
				System.out.println("结束");
				we = null;
			}
		}while(we != null);
		
	}

  

posted on 2015-06-29 19:12  乔叶叶  阅读(933)  评论(0编辑  收藏  举报

导航