本文介紹了Selenium chromeDriver打開速度比直接在Chrome瀏覽器中打開網(wǎng)站慢得多的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我在打開網(wǎng)站時(shí)遇到了一個(gè)關(guān)于Selenium Webdriver速度的令人厭惡的問題。
我正在測(cè)試的網(wǎng)站是內(nèi)部網(wǎng)站,因此您無法訪問。為了詳細(xì)描述我的問題,我將該網(wǎng)站稱為ABC
。
當(dāng)我在Chrome瀏覽器中鍵入ABC
的URL時(shí),僅需1秒即可打開此網(wǎng)站。
在TestNG中,我的Selenium客戶端如下所示:
String ABC = "ABC'S URL";
String chromeDriverPath = "C:\selenium\chromedriver.exe" ;
System.out.println("start selenium");
File file = new File(chromeDriverPath);
System.setProperty("webdriver.chrome.driver",file.getAbsolutePath());
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
webDriver driver = new ChromeDriver(options);
driver.get(ABC);
然后,Chrome將由自動(dòng)化測(cè)試軟件控制。在示意圖上,會(huì)有一條注釋寫著waiting for staticxx.fackbook.com
或waiting for www.facebook.com
。
1分鐘后,ABC
網(wǎng)站已成功加載。我檢查了F12
工具,在控制臺(tái)中它顯示為staticxx.facebook.com/connect/xd_arbiter/r/0F7S7QWJ0Ac.js?version=42#channel=f38f3479a8af658&origin=http%
。
Failed to load resource: the server responded with a status of 503 (Service Unavailable)
有沒有什么Selenium API可以避免加載某些Web資源?
或者,我是否可以在瀏覽器上進(jìn)行一些配置以停止加載某些Web資源?
提前感謝大家!
推薦答案
以下是您問題的答案:
為了避免加載某些網(wǎng)站,您可以利用Chrome瀏覽器的一個(gè)功能,調(diào)整pageLoadStrategy
到DesiredCapabilities
類,設(shè)置為none
,如下所示:
String ABC = "ABC'S URL";
String chromeDriverPath = "C:\selenium\chromedriver.exe" ;
System.out.println("start selenium");
File file = new File(chromeDriverPath);
System.setProperty("webdriver.chrome.driver",file.getAbsolutePath());
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
capabilities.setCapability("pageLoadStrategy", "none");
webDriver driver = new ChromeDriver(capabilities);
driver.get(ABC);
如果這回答了您的問題,請(qǐng)讓我知道。
這篇關(guān)于Selenium chromeDriver打開速度比直接在Chrome瀏覽器中打開網(wǎng)站慢得多的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,