使用js獲取偽元素的content


在測試過程中有時候會遇到反爬蟲機制,一些元素會使用偽元素,這樣在定位元素的時候會定位不到,這時候就要使用js來幫助定位,獲取到想要的元素

下面是部分代碼

//使用js獲取偽元素的content
String script = "return window.getComputedStyle(document.querySelector('.myTips'),':after').getPropertyValue('content')";
JavascriptExecutor js = (JavascriptExecutor) driver;
String content = (String) js.executeScript(script);
System.out.println(content);
View Code

 

 

放心使用,轉載請說明


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM