public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.ie.driver","C:\\Program Files\\Internet Explorer\\IEDriverServer.exe");
DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
webdriver = new InternetExplorerDriver(ieCapabilities);
String filePath = "E:\\assetid.txt";
String Gettime = "E:\\Gettime.txt";
readTxtFile(filePath);
}
public static String readTxtFile(String filePath){
try {
String encoding="GBK";
File file=new File(filePath);
if(file.isFile() && file.exists()){ //判断文件是否存在
InputStreamReader read = new InputStreamReader(
new FileInputStream(file),encoding);//考虑到编码格式
BufferedReader bufferedReader = new BufferedReader(read);
String lineTxt = null;
while((lineTxt = bufferedReader.readLine()) != null){
webdriver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
String url = "http://49.4.131.113:8234/common/ViewAsset.action?assetId=";
// String url = "http://59.108.91.203:8234/common/ViewAsset.action?assetId=";
addstring = lineTxt;
url=url+addstring;
Gettime(url);
System.out.println(url);
webdriver.get(url);
String getTime = webdriver.findElement(By.xpath("//*[@id='categoryMap']/div/div/div/div[2]/div[2]")).getText();
System.out.println(getTime);
Gettime(getTime);
}
read.close();
}else{
System.out.println("找不到指定的文件");
}
} catch (Exception e) {
System.out.println("读取文件内容出错");
e.printStackTrace();
}
return addstring;
}
public static void Gettime(String getTime){
String s1 = new String();
String s =new String();
try {
File f = new File("E:\\Gettime.txt");
// if(f.exists())
//
// { System.out.print("文件存在"); }
// else
// {
// System.out.print("文件不存在");
// f.createNewFile();//不存在则创建 }
// }
BufferedReader input = new BufferedReader(new FileReader(f));
while((s = input.readLine())!=null)
{
s1 += s +"\n";
}
input.close();
s1 += getTime+"\n";
BufferedWriter output = new BufferedWriter(new FileWriter(f));
output.write(s1);
output.close();
}
catch (Exception e) { e.printStackTrace(); }
}
}