在selenium中设置html5 的hidden属性

来源:互联网 发布:电脑桌面软件 编辑:程序博客网 时间:2024/06/08 02:24

网页源代码:

<span class="input-style">http://edge.convers....../0/299/manifest.m3u8</span>

<span hidden="true" id="cdns">http://edge.conversant.swiftserve.com/aaaa/fc-aaaa/d/5297/0/299/manifest.m3u8</span>

在selenium中用javascript的调用,代码如下:

js.executeScript("var text= document.getElementById('cdns'); text.removeAttribute(\"hidden\"); ");

System.out.println(wd.findElement(By.xpath("//div[@id='"+distToID+"']/div/div[2]/div/span[@id='cdns']")).getAttribute("hidden"));
System.out.println(wd.findElement(By.xpath("//div[@id='"+distToID+"']/div/div/table/tbody/tr["+i+"]/th")).getText()+".m3u8 = " +wd.findElement(By.xpath("//div[@id='"+distToID+"']/div/div[2]/div/span[@id='cdns']")).getText());


console的输出信息如下:

null //输出hidden属性,为null 
main.m3u8 = http://edge.conversant.swiftserve.com/aaaa/fc-aaaa/Aaaa_cdnresult/5293/0/300/manifest.m3u8 //输出显示的m3u8

值得注意的是,即使用document.getElementById('cdns').hidden='false' 的语句也没有产生变化,输出hidden=true


网上参考信息:

hidden属性在html5中,只要存在,就是隐藏效果,而不论值为多少

要显示元素,要删除hidden属性,而不是设置为false

1
2
3
4
5
6
7
8
9
10
<script type="text/javascript" async="true">
function qq_onclick(){
var text_2=document.getElementById("text_1");
text_2.removeAttribute("hidden");
}
function qq_close(){
var text_1=document.getElementById("text_1");
text_1.setAttribute("hidden",true);
}
</script>


0 0
原创粉丝点击