在selenium中设置html5 的hidden属性

网页源代码:

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值