使用javascript从静态HTML页面编辑本地xml文件时出错
我在本地存储(硬盘)上有一个静态html页面。我这里没有使用任何类型的服务器。除此之外,我还有一个名为testng.xml的xml文件,我需要在单击按钮时使用javascript从html编辑该文件 我需要将使用javascript从静态HTML页面编辑本地xml文件时出错,javascript,java,xml,selenium-webdriver,testng,Javascript,Java,Xml,Selenium Webdriver,Testng,我在本地存储(硬盘)上有一个静态html页面。我这里没有使用任何类型的服务器。除此之外,我还有一个名为testng.xml的xml文件,我需要在单击按钮时使用javascript从html编辑该文件 我需要将标记替换为标记,或者根据用户通过网页上的复选框进行选择,将标记替换为标记。然后单击按钮执行testng xml 从html按钮调用该函数,如下所示 <input type="submit" onclick="editTestNG()" value="Execute Selected T
标记替换为
标记,或者根据用户通过网页上的复选框进行选择,将
标记替换为
标记。然后单击按钮执行testng xml
从html按钮调用该函数,如下所示
<input type="submit" onclick="editTestNG()" value="Execute Selected Tests">
我能够在z和y变量中检索xml文件和元素。同样在第二个for
循环中,将打印包含xml节点名称和属性的输出。但在y变量中获取xml数据后,我无法获取或使用任何html页面元素,如复选框
x.length
的值最初为140,y.length
为7,但随后x.length
变为0,我的第一个for
循环不会执行
我无法理解为什么在获取xml数据后无法访问html元素。我从未尝试过,但根据我的理解,您可以创建一个bash文件,然后使用jsp代码生成该bash文件。在HTML中添加该jsp代码 参考:- 现在,正如您所说,“我需要准备一个HTML用户界面,带有复选框,用于选择或取消选择要运行的测试,并通过单击按钮来执行它们” 为此,您可能需要创建不同的testng套件,相应地,您需要分别创建更多的bash 参考:-
<script type="text/javascript">
function editTestNG()
{
xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", "testng.xml", false);
xmlHttp.send();
xmlDoc = xmlHttp.responseXML;
txt = "";
x = document.getElementsByName("check");
document.write(x.length + "<br>"); // x.length is number of checkboxes on html page
z = xmlDoc.getElementsByTagName("run")[1];
y = z.children;
document.write(y.length + "<br>"); // y.length is the number of xml child nodes
document.write(x.length + "<br>"); // x.length is number of checkboxes on html page
for(i=0;i<x.length;i++)
{
document.write("abc");
if(x[i].type == 'checkbox')
{
document.writeln("def");
if(x[i].checked == "true" && y[i].nodeName == "exclude")
{
document.writeln("ghi");
txt = y[i].getAttribute("name");
newTag = xmlDoc.createElement("include");
newTag.setAttribute("name",txt);
p = z.replaceChild(newTag, y[i]);
document.write(p.nodeName+"<br>")
document.write(newTag.nodeName + "::"+ newTag.getAttribute("name")+"<br>");
}
if(x[i].checked == "false" && y[i].nodeName == "include")
{
document.writeln("jkl");
txt = y[i].getAttribute("name");
newTag = xmlDoc.createElement("exclude");
newTag.setAttribute("name",txt);
p = z.replaceChild(newTag, y[i]);
document.write(p.nodeName+"<br>")
document.write(newTag.nodeName + "::"+ newTag.getAttribute("name")+"<br>");
}
}
}
y = z.children;
for(i=0;i<y.length;i++)
{
document.writeln("<br>"+y[i].nodeName + " ## "+ y[i].getAttribute("name")+"<br>");
}
}
</script>
140
7
0
exclude ## Group_CCMS_Login
exclude ## Group_CCR_Create_New
exclude ## Group_CCR_Create_New_EngType_M
exclude ## Group_CCR_Create_New_EngType_P
exclude ## Group_Full_ID_Search
include ## Group_Run_Query
exclude ## Group_Dup_Undup