我知道这可能很简单,但是我似乎找不到我做错了什么。
我正在将网页的输出与文本文件的内容进行比较。我有以下代码,似乎对于网页的每个结果,bufferedreader 都会循环一次。一旦我发布代码和结果,这将不那么令人困惑。
代码
String docOne = driver.findElement(By.xpath("/html/body/div[2]/div/div[2]/div/div[4]/div[2]/div/div/div/div/div[2]/div/div/div/h5")).getAttribute("textContent").toString();
String docTwo = driver.findElement(By.xpath("/html/body/div[2]/div/div[2]/div/div[4]/div[2]/div/div/div/div/div[2]/div/div[2]/div/h5")).getAttribute("textContent").toString();
String docThree = driver.findElement(By.xpath("/html/body/div[2]/div/div[2]/div/div[4]/div[2]/div/div/div/div/div[2]/div/div[3]/div/h5")).getAttribute("textContent").toString();
String docFour = driver.findElement(By.xpath("/html/body/div[2]/div/div[2]/div/div[4]/div[2]/div/div/div/div/div[2]/div/div[4]/div/h5")).getAttribute("textContent").toString();
String docFive = driver.findElement(By.xpath("/html/body/div[2]/div/div[2]/div/div[4]/div[2]/div/div/div/div/div[2]/div/div[5]/div/h5")).getAttribute("textContent").toString();
String docSix = driver.findElement(By.xpath("/html/body/div[2]/div/div[2]/div/div[4]/div[2]/div/div/div/div/div[2]/div/div[6]/div/h5")).getAttribute("textContent").toString();
String docSeven = driver.findElement(By.xpath("/html/body/div[2]/div/div[2]/div/div[4]/div[2]/div/div/div/div/div[2]/div/div[7]/div/h5")).getAttribute("textContent").toString();
String docEight = driver.findElement(By.xpath("/html/body/div[2]/div/div[2]/div/div[4]/div[2]/div/div/div/div/div[2]/div/div[8]/div/h5")).getAttribute("textContent").toString();
String docNine = driver.findElement(By.xpath("/html/body/div[2]/div/div[2]/div/div[4]/div[2]/div/div/div[2]/div/div[2]/div/div/div/h5")).getAttribute("textContent").toString();
try (BufferedReader br = new BufferedReader(new FileReader("/Users/vhaislsalisc/Documents/CDWProductionDomainsRequiredDocs.txt"))) {
String sCurrentLine;
while ((sCurrentLine = br.readLine()) != null) {
System.out.println("Webpage: " + docOne + " Required Doc: " + sCurrentLine);
System.out.println("Webpage: " + docTwo + " Required Doc: " + sCurrentLine);
System.out.println("Webpage: " + docThree + " Required Doc: " + sCurrentLine);
System.out.println("Webpage: " + docFour + " Required Doc: " + sCurrentLine);
System.out.println("Webpage: " + docFive + " Required Doc: " + sCurrentLine);
System.out.println("Webpage: " + docSix + " Required Doc: " + sCurrentLine);
System.out.println("Webpage: " + docSeven + " Required Doc: " + sCurrentLine);
System.out.println("Webpage: " + docEight + " Required Doc: " + sCurrentLine);
System.out.println("Webpage: " + docNine + " Required Doc: " + sCurrentLine);
}
br.close();
} catch (IOException e) {
System.err.println("Error: " + e.getMessage());
}
结果
Webpage: Research Request Memo (File Document) Required Doc: Research Request Memo (File Document)
Webpage: Research Study Institutional Review Board (IRB) Approval Letter (File Document) Required Doc: Research Request Memo (File Document)
Webpage: Sample Informed Consent and HIPAA Authorization (File Document) Required Doc: Research Request Memo (File Document)
Webpage: Research and Development (RD) Committee Approval Letter (File Document) Required Doc: Research Request Memo (File Document)
Webpage: Data Use Agreement (File Document) Required Doc: Research Request Memo (File Document)
Webpage: IRB Approval of Waiver of HIPAA-Compliant Authorization (File Document) Required Doc: Research Request Memo (File Document)
Webpage: Research Protocol (File Document) Required Doc: Research Request Memo (File Document)
Webpage: CDW-Domain Checklist (File Document) Required Doc: Research Request Memo (File Document)
Webpage: VA Form 9957 (File Document) Required Doc: Research Request Memo (File Document)
Webpage: Research Request Memo (File Document) Required Doc: Research Study Institutional Review Board (IRB) Approval Letter (File Document)
Webpage: Research Study Institutional Review Board (IRB) Approval Letter (File Document) Required Doc: Research Study Institutional Review Board (IRB) Approval Letter (File Document)
Webpage: Sample Informed Consent and HIPAA Authorization (File Document) Required Doc: Research Study Institutional Review Board (IRB) Approval Letter (File Document)
Webpage: Research and Development (RD) Committee Approval Letter (File Document) Required Doc: Research Study Institutional Review Board (IRB) Approval Letter (File Document)
Webpage: Data Use Agreement (File Document) Required Doc: Research Study Institutional Review Board (IRB) Approval Letter (File Document)
Webpage: IRB Approval of Waiver of HIPAA-Compliant Authorization (File Document) Required Doc: Research Study Institutional Review Board (IRB) Approval Letter (File Document)
Webpage: Research Protocol (File Document) Required Doc: Research Study Institutional Review Board (IRB) Approval Letter (File Document)
Webpage: CDW-Domain Checklist (File Document) Required Doc: Research Study Institutional Review Board (IRB) Approval Letter (File Document)
Webpage: VA Form 9957 (File Document) Required Doc: Research Study Institutional Review Board (IRB) Approval Letter (File Document)
等等通过文件的其余部分
所以只是想知道我做了什么菜鸟,以及如何修复它,以便它只通过文件一次并且所有内容都与来自网页的内容相匹配?