[Selenium]如何实现上传本地文件

public void uploadLocalFileToServer(String uploadFileName){
		String AutomationPath = System.getProperty("user.dir");
		String filePath=AutomationPath+"\\src\\test\\resources\\testData\\"+uploadFileName;
		logger.info("Upload file path : "+filePath);
		WebElement magnifyIcon = page.getMagnifyIconOfSampleReport();
		magnifyIcon.sendKeys(filePath);
		Assert.assertEquals(page.getSampleReportTxtInput().getAttribute("value"),uploadFileName,uploadFileName+" should be listed in Sample Report .");
		Assert.assertTrue(page.getSampleReportDeleteIcon().isDisplayed(), uploadFileName+" should be listed in Sample Report with a delete icon on the right.");
	}

 

public WebElement getMagnifyIconOfSampleReport(){
		return SeleniumUtil.waitForElementPresent(driver, By.cssSelector("div#tmpmgrDiv div.upsmpbtnc a#upSmp.filea input.file"));
	}

 

posted on 2014-05-19 17:24  张缤分  阅读(744)  评论(0)    收藏  举报

导航