【发布时间】:2015-12-05 22:00:46
【问题描述】:
我在 Java Selenium Webdriver 中动态生成 HTML 文件。 HTML 文件有两个 div 标签,每个标签都有自己唯一的 id 属性。
我想稍后在我的代码中根据它们的 id 将 HTML 文本动态添加到这些 div 标签中。
这可以实现吗?如果是的话,有人可以为我指出如何实现这一目标的正确方向吗?如果不是,有什么替代方法可以实现这一目标?
我正在努力解决这种情况。我确实需要能够根据 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
}
【问题讨论】:
-
你需要展示你到目前为止所做的事情。
-
到目前为止,我在 Java 中有两种方法,一种方法是创建具有基本布局的 HTML 文件,第二种方法是动态地将数据附加到该 HTML 文件中。我想了解我是否可以以某种方式访问具有唯一 ID 的第二种方法中的 div 标签,并开始在该 div 标签中附加数据或其他标签。
-
@jgabb 请参考上面的代码sn -p
-
这与 Selenium 无关!您需要 Google 如何正确编写 XML 文件 - HTML 是 XML 的超集。
标签: java html selenium selenium-webdriver