网页源代码:

<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>


Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐