简体   繁体   中英

avoid opening the browser while running selenium webDriver test cases

i have been getting a lot of help from you guys and i am really glad. have passed these huddles,

web page source downloaded through Jsoup is not equal to the actual web page source

How to download a Web page source using Selenium

and now i am finally here for the last huddle (hopefully)

while running the selenium test case, like this,

 WebDriver driver = new FirefoxDriver();
        FluentWebDriver fwd = new FluentWebDriver(driver);

        driver.manage().timeouts().implicitlyWait(5L, TimeUnit.SECONDS);
        driver.get("http://www.justdial.com/Bangalore/Tape-Dealers-%3Cnear%3E-Bangalore-City-Railway-Station/ct-12976/page-5");

       String res = driver.getPageSource();

it opens up the web browser and starts downloading all the images that are there in the page and caues a delay for the source code to be downloaded from my java program. how can i avoid opening up my browser in this scenario?? i just want the page source and NO graphical content. and hence avoid the delay too... please help!! thanks in advance!!

I haven´t used FluentWebDriver but I guess you could try replacing the FirefoxDriver with the HtmlUnitDriver:

Replace:

WebDriver driver = new FirefoxDriver();

With:

HtmlUnitDriver driver = new HtmlUnitDriver();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM