我在Java Selenium Webdriver中動態生成一個HTML文件。 HTML文件有兩個div標籤,每個標籤都有自己唯一的id屬性。如何將HTML文本附加到Java中的div標記中
我想動態地添加HTML文本到這些div標記根據他們的id在稍後的代碼中。
這可以實現嗎?如果是的話,有人可以指出我正確的方向如何實現這一目標?如果否,那麼實現這一目標的另一種方法是什麼?
我正在努力解決這種情況。我真的需要能夠動態地將數據附加到基於div標籤的HTML頁面。
在此先感謝!
public void createsummaryfile(String report,String path) throws IOException{
File summary;
summary = new File(filepath);
if(!summary.exists()){
summary.createNewFile();
}
BufferedWriter bw = new BufferedWriter(new FileWriter(summary));
bw.write("<!DOCTYPE html>");
bw.write("<html><head><h1 align=center>EDC Reports Test Case Execution Summary</h1>");
bw.write("<style>#report_table{height: 300px;left: 1em;position: relative;top: 5em;width: 300px;}#report{height: 300px;left: 20em;position: relative;top: -15em;width: 300px;}</style></head>");
bw.write("<body><div id=report_table><table align=center border=1><tbody><tr><th>Report Name</th></tr></div>");
bw.write("<body><div id=report_display></div>");
bw.write("</html>");
bw.close();
}
public void populate_summary(String report,String path) throws IOException{
File summary_report = new File(filepath);
BufferedWriter br = new BufferedWriter(new FileWriter(summary_report,true));
//Here I need to access the div tags by their id's and start appending data
}
您需要展示迄今爲止所做的工作。 – jgabb
截至目前,我在Java中有兩種方法,一種是使用基本佈局創建HTML文件的方法,另一種方法是將數據動態附加到該HTML文件。 我想了解,如果我可以用第二種方法以其獨特的ID訪問div標籤,並開始在div標籤內附加數據或其他標籤。 –
@jgabb請參考上面的代碼片段 –