[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"));

	}

 

你可能感兴趣的:(selenium)