How can I capture network traffic of a specific…
We can capture network traffic on a specific page using Selenium webdriver in Python. To achieve this, we take the help of the JavaScript Executor. Selenium can execute JavaScript commands with the help of the execute_script method.
JavaScript command to be executed is passed as a parameter to this method. To capture the network traffic, we have to pass the command: return window.performance.getEntries() as a parameter to the execute_script method.
Syntax
r = driver.execute_script("return window.performance.getEntries();")
Example
Code Implementation
from selenium import webdriver
#configure chromedriver path
driver = webdriver.Chrome(executable_path='F:\\Work Environment\\MyProject\\QA_Round\\chromedriver.exe')
#implicit wait
driver.implicitly_wait(0.5)
#url launch
driver.get("https://www.google.com/")
#JavaScript command to traffic
r = driver.execute_script("return window.performance.getEntries();")
for res in r:
print(res['name'])
#browser close
driver.close()
Output:
DevTools listening on ws://127.0.0.1:56201/devtools/browser/4da6ea83-b808-4ec5-8ae3-5d9a644abfe6
https://www.google.com/
https://www.google.com/xjs//js/k=xjs.s.en_GB.jS3OP7-RYWo.O/am=CCgA2EAAAAQzAAAAAAAAAIBA4MEAIAASSQAAAAAAQQAARACXAwQAAADwEZ8BAv4GAEbQhAsAAAAAAAAIwCXFUINEQQAIAAAAABCrqSsGgEAg/d=1/ed=1/dg=2/esmo=1/br=1/rs=ACT90oHGOS_vgEofFOFQIJLil3vVNM6d2g/m=cdos,dpf,hsm,jsa,d,csi https://www.google.com/logos/doodles/2022/get-vaccinated-wear-a-mask-save-lives-january-17-copy-6753651837109683-law.gif https://www.google.com/images/searchbox/desktop_searchbox_sprites318_hr.webp first-paint first-contentful-paint https://www.gstatic.com/og//js/k=og.qtm.en_US.9pElbIcw614.O/rt=j/m=qabr,q_dnp,qcwid,qapid,qald/exm=qaaw,qadd,qaid,qein,qhaw,qhbr,qhch,qhga,qhid,qhin,qhpr/d=1/ed=1/rs=AA2YrTsg7Vn-zTR579BY_X_YWcvF5v0w8g
https://www.gstatic.com/og//ss/k=og.qtm.ofT4jE96td0.L.W.O/m=qcwid/excm=qaaw,qadd,qaid,qein,qhaw,qhbr,qhch,qhga,qhid,qhin,qhpr/d=1/ed=1/ct=zgms/rs=AA2YrTvubo9qkY4L_hGiF_giXJgemAw0Bw https://www.google.com/gen_204?s=webhp&t=aft&atyp=csi&ei=XfzmYcrbD7WD4-EP-PSZwAY&rt=wsrt.1279,aft.212,afti.212,prt.188&imn=2&ima=1&imad=0&aftp=620&bl=UJOX O7jPNb kDcP9b https://www.google.com/complete/search?q&cp=0&client=gws-wiz&xssi=t&hl=en-IN&authuser=0&psi=XfzmYcrbD7WD4-EP-PSZwAY.1642527829192&nolsbt=1&dpr=1 https://www.google.com/xjs//js/k=xjs.s.en_GB.jS3OP7-RYWo.O/ck=xjs.s.O9zdDYGJ4io.L.W.O/am=CCgA2EAAAAQzAAAAAAAAAIBA4MEAIAASSQAAAAAAQQAARACXAwQAAADwEZ8BAv4GAEbQhAsAAAAAAAAIwCXFUINEQQAIAAAAABCrqSsGgEAg/d=1/exm=cdos,csi,d,dpf,hsm,jsa/esmo=1/ed=1/dg=2/br=1/rs=ACT90oEY3toiTZYMSoFCT5U_006iXLyKLw/ee=yxTchf:KUM7Z;qddgKe:x4FYXe;uY49fb:COQbmf;wR5FRb:TtcOte;iFQyKf:QIhFr;dIoSBb:ZgGg9b;eBAeSb:Ck63tb;g8nkx:U4MzKc;wQlYve:aLUfP;kbAm9d:MkHyGd;F9mqte:UoRcbe;sTsDMc:kHVSUb;vfVwPd:OXTqFb;dtl0hd:lLQWFe;q92ire:wPVhqc;pXdRYb:JKoKVe;KpRAue:Tia57b;EVNhjf:pw70Gc;nAFL3:s39S4;LQlyHd:KJbvFf;aZ61od:arTwJ;JXS8fb:Qj0suc;rQSrae:C6D5Fc;qavrXe:zQzcXe;pNsl2d:j9Yuyc;UDrY1c:eps46d;nKl0s:xxrckd;Nyt6ic:jn2sGd;w3bZCb:ZPGaIb;imqimf:jKGL2e;KQzWid:mB4wNe;Np8Qkd:Dpx6qc;BjwMce:cXX2Wb;oGtAuc:sOXFj;whEZac:iuHkw;Fmv9Nc:O1Tzwc;hK67qb:QWEO5b;jVtPve:wQ95P;R4IIIb:QWfeKf;xbe2wc:wbTLEd;tosKvd:ZCqP3;NSEoX:lazG7b;kCQyJ:ueyPK;oSUNyd:fTfGO;SJsSc:H1GVub;SMDL4c:fTfGO;NPKaK:PVlQOd;zOsCQe:Ko78Df;WCEKNd:I46Hvd;LBgRLc:XVMNvd;TxfV6d:YORN0b;GleZL:J1A7Od;qaS3gd:yiLg6e;VGRfx:VFqbr;aAJE9c:WHW6Ef;BgS6mb:fidj5d;z97YGf:oug9te;CxXAWb:YyRLvc;Pguwyb:Xm4ZCd;VN6jIc:ddQyuf;SLtqO:Kh1xYe;WDGyFe:jcVOxd;DULqB:RKfG5c;gaub4:TN6bMe;DpcR3d:zL72xf;hjRo6e:F62sG;w9w86d:dt4g2b;lkq0A:Z0MWEf;eHDfl:ofjVkb;SNUn3:x8cHvb;LEikZe:byfTOb,lsjVmc;io8t5d:sgY6Zb;j7137d:KG2eXe;Oj465e:KG2eXe;sP4Vbe:VwDzFe;kMFpHd:blwjVc/m=DhPYme,EkevXb,GU4Gab,NzU6V,aa,abd,async,dvl,fKZehd,mu,pHXghd,sb_wiz,sf,sonic,spch?xjs=s1
https://www.google.com/client_204?&atyp=i&biw=1034&bih=575&ei=XfzmYcrbD7WD4-EP-PSZwAY
https://www.google.com/xjs//js/k=xjs.s.en_GB.jS3OP7-RYWo.O/ck=xjs.s.O9zdDYGJ4io.L.W.O/am=CCgA2EAAAAQzAAAAAAAAAIBA4MEAIAASSQAAAAAAQQAARACXAwQAAADwEZ8BAv4GAEbQhAsAAAAAAAAIwCXFUINEQQAIAAAAABCrqSsGgEAg/d=1/exm=DhPYme,EkevXb,GU4Gab,NzU6V,aa,abd,async,cdos,csi,d,dpf,dvl,fKZehd,hsm,jsa,mu,pHXghd,sb_wiz,sf,sonic,spch/esmo=1/ed=1/dg=2/br=1/rs=ACT90oEY3toiTZYMSoFCT5U_006iXLyKLw/ee=yxTchf:KUM7Z;qddgKe:x4FYXe;uY49fb:COQbm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en_204?atyp=i&ei=XfzmYcrbD7WD4-EP-PSZwAY&dt19=2&zx=1642527829299 https://www.google.com/client_204?cs=1 https://apis.google.com//scs/abc-static//js/k=gapi.gapi.en.h3Hb0D_ghuM.O/m=gapi_iframes,googleapis_client/rt=j/sv=1/d=1/ed=1/rs=AHpOoo8HKYs3uYwO3D8vrT9sPLRNofSg0A/cb=gapi.loaded_0 https://www.google.com/xjs//js/k=xjs.s.en_GB.jS3OP7-RYWo.O/ck=xjs.s.O9zdDYGJ4io.L.W.O/am=CCgA2EAAAAQzAAAAAAAAAIBA4MEAIAASSQAAAAAAQQAARACXAwQAAADwEZ8BAv4GAEbQhAsAAAAAAAAIwCXFUINEQQAIAAAAABCrqSsGgEAg/d=1/exm=DhPYme,EkevXb,GU4Gab,LtQuz,NzU6V,VsqSCc,aa,abd,async,cdos,csi,d,dpf,dvl,fKZehd,fXO0xe,hsm,jsa,kQvlef,mu,pHXghd,sb_wiz,sf,sonic,spch/esmo=1/ed=1/dg=2/br=1/rs=ACT90oEY3toiTZYMSoFCT5U_006iXLyKLw/ee=yxTchf:KUM7Z;qddgKe:x4FYXe;uY49fb:COQbmf;wR5FRb:TtcOte;iFQyKf:QIhFr;dIoSBb:ZgGg9b;eBAeSb:Ck63tb;g8nkx:U4MzKc;wQlYve:aLUfP;kbAm9d:MkHyGd;F9mqte:UoRcbe;sTsDMc:kHVSUb;vfVwPd:OXTqFb;dtl0hd:lLQWFe;q92ire:wPVhqc;pXdRYb:JKoKVe;KpRAue:Tia57b;EVNhjf:pw70Gc;nAFL3:s39S4;LQlyHd:KJbvFf;aZ61od:arTwJ;JXS8fb:Qj0suc;rQSrae:C6D5Fc;qavrXe:zQzcXe;pNsl2d:j9Yuyc;UDrY1c:eps46d;nKl0s:xxrckd;Nyt6ic:jn2sGd;w3bZCb:ZPGaIb;imqimf:jKGL2e;KQzWid:mB4wNe;Np8Qkd:Dpx6qc;BjwMce:cXX2Wb;oGtAuc:sOXFj;whEZac:iuHkw;Fmv9Nc:O1Tzwc;hK67qb:QWEO5b;jVtPve:wQ95P;R4IIIb:QWfeKf;xbe2wc:wbTLEd;tosKvd:ZCqP3;NSEoX:lazG7b;kCQyJ:ueyPK;oSUNyd:fTfGO;SJsSc:H1GVub;SMDL4c:fTfGO;NPKaK:PVlQOd;zOsCQe:Ko78Df;WCEKNd:I46Hvd;LBgRLc:XVMNvd;TxfV6d:YORN0b;GleZL:J1A7Od;qaS3gd:yiLg6e;VGRfx:VFqbr;aAJE9c:WHW6Ef;BgS6mb:fidj5d;z97YGf:oug9te;CxXAWb:YyRLvc;Pguwyb:Xm4ZCd;VN6jIc:ddQyuf;SLtqO:Kh1xYe;WDGyFe:jcVOxd;DULqB:RKfG5c;gaub4:TN6bMe;DpcR3d:zL72xf;hjRo6e:F62sG;w9w86d:dt4g2b;lkq0A:Z0MWEf;eHDfl:ofjVkb;SNUn3:x8cHvb;LEikZe:byfTOb,lsjVmc;io8t5d:sgY6Zb;j7137d:KG2eXe;Oj465e:KG2eXe;sP4Vbe:VwDzFe;kMFpHd:blwjVc/m=aLUfP?xjs=s2
In Java:
package RK1.Building_a_selenium_project;
import org.testng.annotations.Test;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.logging.LogEntry;
import org.openqa.selenium.logging.LogType;
import org.openqa.selenium.logging.LoggingPreferences;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.Reporter;
import org.testng.annotations.AfterTest;
public class NetworkState {
public static WebDriver driver;
@SuppressWarnings("deprecation")
@Test
public void test1() {
System.setProperty("webdriver.chrome.driver", "F:\\Work Environment\\MyProject\\QA_Round\\chromedriver.exe");
DesiredCapabilities caps = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.PERFORMANCE, Level.ALL);
options.setCapability( "goog:loggingPrefs", logPrefs );
caps.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
driver = new ChromeDriver(caps);
driver.navigate().to("https://www.google.com/");
List<LogEntry> entries = driver.manage().logs().get(LogType.BROWSER).getAll();
System.out.println(entries.size() + " " + LogType.PERFORMANCE + " log entries found");
for (LogEntry entry : entries) {
System.out.println(new Date(entry.getTimestamp()) + " " + entry.getLevel() + " " + entry.getMessage());
}
}
@AfterTest
public void afterTest() {
driver.close();
driver.quit();
Reporter.log("Test is complete: Exit");
}
}
8 COMMENTS
http://slkjfdf.net/ – Oqibba Oyahure gcc.emjb.testingbuddy.co.in.jcm.ny http://slkjfdf.net/
I抎 should verify with you here. Which is not something I usually do! I get pleasure from reading a submit that can make folks think. Also, thanks for allowing me to comment!
I know this if off topic but I’m looking into starting my own blog and was wondering what all is needed to get set up? I’m assuming having a blog like yours would cost a pretty penny? I’m not very web savvy so I’m not 100 certain. Any tips or advice would be greatly appreciated. Appreciate it
I cling on to listening to the news update talk about getting free online grant applications so I have been looking around for the most excellent site to get one. Could you tell me please, where could i find some?
Hello, you used to write fantastic, but the last several posts have been kinda boring?I miss your great writings. Past several posts are just a little bit out of track! come on!
I’ve come across that right now, more and more people will be attracted to cameras and the industry of taking pictures. However, really being a photographer, you have to first devote so much time deciding which model of digital camera to buy in addition to moving store to store just so you can buy the lowest priced camera of the trademark you have decided to pick out. But it does not end just there. You also have to take into consideration whether you should obtain a digital video camera extended warranty. Thanks a bunch for the good suggestions I acquired from your blog site.
Thanks for the different tips provided on this weblog. I have realized that many insurance carriers offer buyers generous deals if they elect to insure several cars with them. A significant quantity of households own several cars these days, specifically those with more mature teenage kids still dwelling at home, along with the savings for policies may soon mount up. So it is good to look for a good deal.
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
Comments are closed.