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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章