/** * Creates a new PhantomJSCommandExecutor. * The PhantomJSCommandExecutor will communicate with the PhantomJS/GhostDriver through the given {@code service}. * * @param service The PhantomJSDriverService to send commands to. */ PhantomJSCommandExecutor(PhantomJSDriverService service) { super(PhantomJSDriver.getCustomCommands(), service.getUrl()); this.service = service; }
/** * Same as {@link PhantomJSDriverService#createDefaultService(org.openqa.selenium.Capabilities)}. * <br> * In this case PhantomJS or GhostDriver can't be searched within the Capabilities, only System * Properties. * * @return A new ChromeDriverService using the default configuration. */ public static PhantomJSDriverService createDefaultService() { return createDefaultService(null); }
/** * Creates a new PhantomJSDriver instance. The {@code service} will be started along with the * driver, and shutdown upon calling {@link #quit()}. * * @param service The service to use. * @param desiredCapabilities The capabilities required from PhantomJS/GhostDriver. */ public PhantomJSDriver(PhantomJSDriverService service, Capabilities desiredCapabilities) { super(new PhantomJSCommandExecutor(service), desiredCapabilities); }
var driver = new PhantomJSDriver(); driver.Url = "http://www.regulations.gov/#!documentDetail;D=APHIS-2013-0013-0083"; driver.Navigate(); //the driver can now provide you with what you need (it will execute the script) //get the source of the page var source = driver.PageSource; //fully navigate the dom var pathElement = driver.FindElementById("some-id");
File phantomjsfile = findPhantomJS(desiredCapabilities, PHANTOMJS_DOC_LINK, PHANTOMJS_DOWNLOAD_LINK); File ghostDriverfile = findGhostDriver(desiredCapabilities, GHOSTDRIVER_DOC_LINK, GHOSTDRIVER_DOWNLOAD_LINK); return new Builder().usingPhantomJSExecutable(phantomjsfile) .usingGhostDriver(ghostDriverfile) .usingAnyFreePort() .withProxy(proxy) .withLogFile(findLogFile()) .withAcceptSslCerts(findAcceptSslCerts(desiredCapabilities)) .usingCommandLineArguments( findCLIArgumentsFromCaps(desiredCapabilities, PHANTOMJS_CLI_ARGS)) .usingGhostDriverCommandLineArguments( findCLIArgumentsFromCaps(desiredCapabilities, PHANTOMJS_GHOSTDRIVER_CLI_ARGS)) .build();
public Response execute(Command command) throws IOException { if (DriverCommand.NEW_SESSION.equals(command.getName())) { service.start(); if (rootCause instanceof ConnectException && "Connection refused".equals(rootCause.getMessage()) && !service.isRunning()) { throw new WebDriverException("The PhantomJS/GhostDriver server has unexpectedly died!", t); } finally { if (DriverCommand.QUIT.equals(command.getName())) { service.stop();
if (!argsContains(this.ghostdriverCommandLineArguments, "port")) { argsBuilder.add(String.format("--port=%d", port)); if (logFile != null && !argsContains(this.ghostdriverCommandLineArguments, "logFile")) { argsBuilder.add(String.format("--logFile=%s", logFile.getAbsolutePath())); if (!argsContains(this.commandLineArguments, "webdriver")) { argsBuilder.add(String.format("--webdriver=%d", port)); if (logFile != null && !argsContains(this.commandLineArguments, "webdriver-logfile")) { argsBuilder.add(String.format("--webdriver-logfile=%s", logFile.getAbsolutePath())); return new PhantomJSDriverService(phantomjs, port, argsBuilder.build(), environment); } catch (IOException e) { throw new WebDriverException(e);
/** * Take screenshot of the current window. * * @param target The target type/format of the Screenshot * @return Screenshot of current window, in the requested format */ @Override public <X> X getScreenshotAs(OutputType<X> target) { // Get the screenshot as base64 and convert it to the requested type (i.e. OutputType<T>) String base64 = (String) execute(DriverCommand.SCREENSHOT).getValue(); return target.convertFromBase64Png(base64); }
checkExecutable(phantomjs); return phantomjs;
// untested Java code, only provides the logic // please debug and refer to the documentation import org.openqa.selenium.Dimension; WebDriver driver = new PhantomJSDriver(); driver.manage().window().setSize(new Dimension(1920, 1080)); // or driver.manage().window().maximize(); driver.get("http://stackoverflow.com/questions/21743350/how-to-set-screen-window-size-when-using-ghostdriver");
/** * Creates a new PhantomJSDriver instance. * * @param desiredCapabilities The capabilities required from PhantomJS/GhostDriver. * @see org.openqa.selenium.phantomjs.PhantomJSDriverService#createDefaultService() for configuration details. */ public PhantomJSDriver(Capabilities desiredCapabilities) { this(PhantomJSDriverService.createDefaultService(desiredCapabilities), desiredCapabilities); }
/** * Creates a new MultiSessionCommandExecutor. * The PhantomJSCommandExecutor will communicate with the PhantomJS/GhostDriver through the given {@code service}. * * @param service The PhantomJSDriverService to send commands to. */ public MultiSessionCommandExecutor(PhantomJSDriverService service) { super(PhantomJSDriver.getCustomCommands(), service.getUrl()); } }
"script", script, "args", Lists.newArrayList(convertedArgs)); return execute(COMMAND_EXECUTE_PHANTOM_SCRIPT, params).getValue();
public static WebDriver getDriver(String browserType, boolean headless){ if ( StringUtils.isEmpty(browserType) || FIREFOX.equals(browserType)) { return new FirefoxDriver(SeleniumBrowserFactory.getBrowserCapabilities(browserType, headless)); } else if (CHROME.equals(browserType)) { return new ChromeDriver(SeleniumBrowserFactory.getBrowserCapabilities(browserType, headless)); } else if (IE.equals(browserType)) { return new InternetExplorerDriver(SeleniumBrowserFactory.getBrowserCapabilities(browserType, false)); } else if (PHANTOMJS.equals(browserType)) { return new PhantomJSDriver(); } else if (SAFARI.equals(browserType)) { return new SafariDriver(); } else if (EDGE.equals(browserType)) { return new EdgeDriver(); } else { throw new RuntimeException(String.format("Unknown browser type: \"%s\"", browserType)); } }
/** * Creates a new PhantomJSDriver instance. * * @param desiredCapabilities The capabilities required from PhantomJS/GhostDriver. * @see org.openqa.selenium.phantomjs.PhantomJSDriverService#createDefaultService() for configuration details. */ public PhantomJSDriver(Capabilities desiredCapabilities) { this(PhantomJSDriverService.createDefaultService(desiredCapabilities), desiredCapabilities); }
/** * Creates a new MultiSessionCommandExecutor. * The PhantomJSCommandExecutor will communicate with the PhantomJS/GhostDriver through the given {@code service}. * * @param service The PhantomJSDriverService to send commands to. */ public MultiSessionCommandExecutor(PhantomJSDriverService service) { super(PhantomJSDriver.getCustomCommands(), service.getUrl()); } }
mDriver = new ChromeDriver(sCaps); } else if (driver.equals(DRIVER_PHANTOMJS)) { mDriver = new PhantomJSDriver(sCaps);
/** * Same as {@link PhantomJSDriverService#createDefaultService(org.openqa.selenium.Capabilities)}. * <p/> * In this case PhantomJS or GhostDriver can't be searched within the Capabilities, only System * Properties. * * @return A new ChromeDriverService using the default configuration. */ public static PhantomJSDriverService createDefaultService() { return createDefaultService(null); }
/** * Creates a new PhantomJSCommandExecutor. * The PhantomJSCommandExecutor will communicate with the PhantomJS/GhostDriver through the given {@code service}. * * @param service The PhantomJSDriverService to send commands to. */ PhantomJSCommandExecutor(PhantomJSDriverService service) { super(PhantomJSDriver.getCustomCommands(), service.getUrl()); this.service = service; }
var driver = new PhantomJSDriver(); driver.Manage().Window.Maximize(); // optional driver.Navigate().GoToUrl("http://stackoverflow.com"); driver.TakeScreenshot().SaveAsFile("screenshot.png", ImageFormat.Png); driver.Quit();