Example usage for org.openqa.selenium Proxy setSocksUsername

List of usage examples for org.openqa.selenium Proxy setSocksUsername

Introduction

In this page you can find the example usage for org.openqa.selenium Proxy setSocksUsername.

Prototype

public Proxy setSocksUsername(String username) 

Source Link

Document

Specifies a username for the SOCKS proxy.

Usage

From source file:com.arifnazarpurwandaru.selenium.MainFrame.java

private void btnSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchActionPerformed

    try {//from ww  w. j  av  a 2s.  c  o  m
        //            MarionetteDriverManager.getInstance().setup();
        System.out.println("Mulai Pencarian...");
        //      Runtime.getRuntime().exec("TASKKILL /F /IM Firefox.exe");
        //      Runtime.getRuntime().exec("TASKKILL /F /IM iexplore.exe");
        //      Runtime.getRuntime().exec("TASKKILL /F /IM iexplore.exe");

        WebDriver driver = null;
        String kereta = ((ComboItem) comboKereta.getSelectedItem()).getValue();

        //use proxy
        if (radioUseProxy.isSelected()) {
            String proxyHost = hostProxy.getText() + ":" + portProxy.getText();
            Proxy proxy = new Proxy();
            proxy.setHttpProxy(proxyHost);
            proxy.setSslProxy(proxyHost);
            proxy.setFtpProxy(proxyHost);
            proxy.setSocksUsername(usernameProxy.getText());
            proxy.setSocksPassword(new String(passwordProxy.getPassword()));

            DesiredCapabilities cap = new DesiredCapabilities();
            cap.setCapability(CapabilityType.PROXY, proxy);

            driver = new ChromeDriver(cap);
        } else {

            //                    driver = new MarionetteDriver();
            driver = new ChromeDriver();
        }
        //       hmin = Integer.valueOf(args[0]).intValue();
        ComboItem link = (ComboItem) comboLink.getSelectedItem();
        driver.get(link.getValue());
        List<WebElement> list = null;
        int counter = 1;
        boolean keeploop = true;
        while (/**list==null || list.size() == 0**/
        keeploop) {

            try {
                Select selectTgl = new Select(driver.findElement(By.name("tanggal")));
                selectTgl.selectByIndex(comboTanggal.getSelectedIndex());

                ComboItem stFrom = (ComboItem) comboStBerangkat.getSelectedItem();
                Select selectFrom = new Select(driver.findElement(By.name("origination")));
                selectFrom.selectByValue(stFrom.getValue());

                ComboItem stTo = (ComboItem) comboStTujuan.getSelectedItem();
                Select selectTo = new Select(driver.findElement(By.name("destination")));
                selectTo.selectByValue(stTo.getValue());

                Select selectAdult = new Select(driver.findElement(By.name("adult")));
                selectAdult.selectByValue("1");

                WebElement element = driver.findElement(By.name("Submit"));
                element.click();
                //          Thread.sleep(1000);
                //tunggu sampe page ready, nandainnya kalo element div dengan css class "itReservationContent" muncul
                WebElement elementForWait = (new WebDriverWait(driver, 1)).until(
                        ExpectedConditions.visibilityOfElementLocated(By.className("itReservationContent")));
                //end wait

                list = driver.findElements(By.className("itButton"));
                if (list != null && list.size() > 0) {
                    List<WebElement> listForm = driver.findElements(By.tagName("form"));
                    for (WebElement form : listForm) {
                        List<WebElement> listInput = form.findElements(By.tagName("input"));
                        for (WebElement input : listInput) {
                            if (input.getAttribute("value").equalsIgnoreCase(kereta)) {
                                WebElement btn = form.findElement(By.className("itButton"));
                                btn.click();
                                System.out.println("========================>KLIK BOOKING");
                                keeploop = false;
                                throw new KlikException("BerhasilKlik");
                            }
                        }
                    }
                }
                System.out.println("==========================> looping ke: " + counter);
                counter++;
            } catch (KlikException ke) {
                System.out.println("================> Masuk Klik Exception");
                keeploop = false;
                break;
            } catch (Exception e) {
                e.printStackTrace();
                System.out.println("===================> Reconecting..." + link.getValue());
                driver.get(link.getValue());
            }
        }

        //       System.out.println("ada keretaaaaaa: "+list.size());
        List<WebElement> listInput = driver.findElements(By.tagName("input"));
        for (WebElement input : listInput) {
            if (input.getAttribute("type").equals("checkbox")) {
                input.click();
                break;
            }
        }
        WebElement lanjut = driver.findElement(By.cssSelector("input[type='submit'][name='booking']"));
        lanjut.click();

        //Ngisi Tikete 
        //Nunggu disit
        //tunggu sampe page ready, nandainnya kalo element div dengan css class "txt_first_name_adult_1" muncul
        WebElement elementForWait = (new WebDriverWait(driver, 3))
                .until(ExpectedConditions.visibilityOfElementLocated(By.id("txt_first_name_adult_1")));
        //end wait
        WebElement namaPenumpang = driver.findElement(By.id("txt_first_name_adult_1"));
        WebElement ktp = driver.findElement(By.id("txt_passport_1"));

        WebElement contactName = driver.findElement(By.id("txt_contact_first_name"));
        WebElement contactEmail = driver.findElement(By.id("txt_contact_email"));
        WebElement contactPhone = driver.findElement(By.id("txt_contact_phone"));
        WebElement contactAddress = driver.findElement(By.id("txt_contact_home_address"));

        namaPenumpang.sendKeys(txtNamaPenumpang.getText());
        ktp.sendKeys(txtNoKTP.getText());
        contactName.sendKeys(txtNamaPenumpang.getText());
        contactEmail.sendKeys(txtEmail.getText());
        contactPhone.sendKeys(txtNoTelp.getText());
        contactAddress.sendKeys(txtAlamat.getText());

        playSound();

        JOptionPane.showMessageDialog(rootPane,
                "Booking sudah tersedia, Silakan inputkan Captcha!! Dan lanjutkan secara manual", "Informasi",
                JOptionPane.INFORMATION_MESSAGE);
        this.setAlwaysOnTop(true);

        System.out.println("DONE");
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.arifnazarpurwandaru.selenium.MainFrame.java

private void btnSearchBiasaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchBiasaActionPerformed

    try {// ww w .  j av a  2  s. c  om
        Runtime.getRuntime().exec("TASKKILL /F /IM Firefox.exe");
        Runtime.getRuntime().exec("TASKKILL /F /IM iexplore.exe");

        WebDriver driver = null;

        //use proxy
        if (radioUseProxy.isSelected()) {
            String proxyHost = hostProxy.getText() + ":" + portProxy.getText();
            Proxy proxy = new Proxy();
            proxy.setHttpProxy(proxyHost);
            proxy.setSslProxy(proxyHost);
            proxy.setFtpProxy(proxyHost);
            proxy.setSocksUsername(usernameProxy.getText());
            proxy.setSocksPassword(new String(passwordProxy.getPassword()));

            DesiredCapabilities cap = new DesiredCapabilities();
            cap.setCapability(CapabilityType.PROXY, proxy);

            driver = new ChromeDriver(cap);
        } else {
            driver = new ChromeDriver();
        }

        ComboItem link = (ComboItem) comboLink.getSelectedItem();
        driver.get(link.getValue());
        List<WebElement> list = null;
        int counter = 1;

        while (list == null || list.size() == 0) {

            try {
                Select selectTgl = new Select(driver.findElement(By.name("tanggal")));
                selectTgl.selectByIndex(comboTanggalBiasa.getSelectedIndex());

                ComboItem ck = (ComboItem) comboStBerangkatBiasa.getSelectedItem();
                Select selectFrom = new Select(driver.findElement(By.name("origination")));
                selectFrom.selectByValue(ck.getValue());

                ComboItem ct = (ComboItem) comboStTujuanBiasa.getSelectedItem();
                Select selectTo = new Select(driver.findElement(By.name("destination")));
                selectTo.selectByValue(ct.getValue());

                Select selectAdult = new Select(driver.findElement(By.name("adult")));
                selectAdult.selectByValue("1");

                WebElement element = driver.findElement(By.name("Submit"));
                element.click();

                //tunggu sampe page ready, nandainnya kalo element div dengan css class "itReservationContent" muncul
                WebElement elementForWait = (new WebDriverWait(driver, 1)).until(
                        ExpectedConditions.visibilityOfElementLocated(By.className("itReservationContent")));
                //end wait

                list = driver.findElements(By.className("itButton"));
                System.out.println("==========================> looping ke: " + counter);
                counter++;
            } catch (Exception e) {
                System.out.println("===================> Reconecting..." + link.getValue());
                driver.get(link.getValue());
            }
        }
        System.out.println("ada keretaaaaaa: " + list.size());
        System.out.println("DONE");
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.qwazr.crawler.web.driver.BrowserDriverBuilder.java

License:Apache License

public BrowserDriver build() throws ReflectiveOperationException, SecurityException {
    BrowserDriverEnum browserType = BrowserDriverEnum.html_unit;

    final WebCrawlDefinition.ProxyDefinition proxyDef;

    DesiredCapabilities capabilities = null;

    if (crawlDefinition != null) {

        // Choose a browser type
        if (crawlDefinition.browser_type != null)
            browserType = crawlDefinition.browser_type;

        proxyDef = selectProxy();//from w  w  w.j a  va  2 s.  c o m

        // Setup the proxy
        if (proxyDef != null) {
            capabilities = checkCapabilities(capabilities);
            org.openqa.selenium.Proxy proxy = new Proxy();
            if (proxyDef.http_proxy != null)
                proxy.setHttpProxy(proxyDef.http_proxy);
            if (proxyDef.ftp_proxy != null)
                proxy.setFtpProxy(proxyDef.ftp_proxy);
            if (proxyDef.ssl_proxy != null)
                proxy.setSslProxy(proxyDef.ssl_proxy);
            if (proxyDef.socks_proxy != null)
                proxy.setSocksProxy(proxyDef.socks_proxy);
            if (proxyDef.socks_username != null)
                proxy.setSocksUsername(proxyDef.socks_username);
            if (proxyDef.socks_password != null)
                proxy.setSocksPassword(proxyDef.socks_password);
            if (proxyDef.no_proxy != null)
                proxy.setNoProxy(proxyDef.no_proxy);
            if (proxyDef.proxy_autoconfig_url != null)
                proxy.setProxyAutoconfigUrl(proxyDef.proxy_autoconfig_url);
            capabilities.setCapability(CapabilityType.PROXY, proxy);
        }

        // Setup the language
        if (crawlDefinition.browser_language != null) {
            capabilities = checkCapabilities(capabilities);
            capabilities.setCapability(AdditionalCapabilities.QWAZR_BROWSER_LANGUAGE,
                    crawlDefinition.browser_language);
            if (browserType == BrowserDriverEnum.phantomjs)
                capabilities.setCapability(
                        PhantomJSDriverService.PHANTOMJS_PAGE_CUSTOMHEADERS_PREFIX + "Accept-Language",
                        crawlDefinition.browser_language);
        }

        // Download images
        if (crawlDefinition.download_images != null) {
            capabilities = checkCapabilities(capabilities);
            if (browserType == BrowserDriverEnum.phantomjs)
                capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_PAGE_SETTINGS_PREFIX + "loadImages",
                        crawlDefinition.download_images);
        }

        // Web security
        if (crawlDefinition.web_security != null) {
            capabilities = checkCapabilities(capabilities);
            if (browserType == BrowserDriverEnum.phantomjs)
                capabilities.setCapability(
                        PhantomJSDriverService.PHANTOMJS_PAGE_SETTINGS_PREFIX + "webSecurityEnabled",
                        crawlDefinition.web_security);
        }

        // Choose a browser name
        if (crawlDefinition.browser_name != null) {
            capabilities = checkCapabilities(capabilities);
            capabilities.setBrowserName(crawlDefinition.browser_name);
        }

        if (crawlDefinition.browser_version != null) {
            capabilities = checkCapabilities(capabilities);
            capabilities.setVersion(crawlDefinition.browser_version);
        }

        // Javascript capability
        if (crawlDefinition.javascript_enabled != null) {
            capabilities = checkCapabilities(capabilities);
            capabilities.setJavascriptEnabled(crawlDefinition.javascript_enabled);
            if (browserType == BrowserDriverEnum.phantomjs)
                capabilities.setCapability(
                        PhantomJSDriverService.PHANTOMJS_PAGE_SETTINGS_PREFIX + "javascriptEnabled",
                        crawlDefinition.javascript_enabled);

        }

    } else
        proxyDef = null;

    if (browserType == BrowserDriverEnum.phantomjs) {
        capabilities = checkCapabilities(capabilities);
        capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS,
                new String[] { "--webdriver-loglevel=NONE", "--ignore-ssl-errors=true" });
    }

    final WebDriver driver = browserType.getNewInstance(capabilities);
    try {
        final BrowserDriver browserDriver = new BrowserDriver(browserType, driver, proxyDef);
        browserDriver.setTimeouts(crawlDefinition.implicitly_wait, crawlDefinition.page_load_timeout,
                crawlDefinition.script_timeout);

        if (crawlDefinition.cookies != null)
            for (Map.Entry<String, String> cookie : crawlDefinition.cookies.entrySet())
                driver.manage().addCookie(new Cookie(cookie.getKey(), cookie.getValue()));

        return browserDriver;
    } catch (Exception e) {
        driver.quit();
        throw e;
    }
}

From source file:org.suren.autotest.web.framework.selenium.CapabilityConfig.java

License:Apache License

/**
 * ?/*from   w  w  w  .j  av  a  2s. c om*/
 * chrome://version/
 */
private void chrome() {
    DesiredCapabilities capability = DesiredCapabilities.chrome();

    ChromeOptions options = new ChromeOptions();
    Iterator<Object> chromeKeys = enginePro.keySet().iterator();
    Proxy proxy = new Proxy();
    while (chromeKeys.hasNext()) {
        String key = chromeKeys.next().toString();
        if (!key.startsWith("chrome")) {
            continue;
        }

        if (key.startsWith("chrome.args")) {
            String arg = key.replace("chrome.args.", "") + "=" + enginePro.getProperty(key);
            if (arg.endsWith("=")) {
                arg = arg.substring(0, arg.length() - 1);
            }
            options.addArguments(arg);
            logger.info(String.format("chrome arguments : [%s]", arg));
        } else if (key.startsWith("chrome.cap.proxy.http")) {
            String val = enginePro.getProperty(key);

            proxy.setHttpProxy(val);
        } else if (key.startsWith("chrome.cap.proxy.ftp")) {
            String val = enginePro.getProperty(key);

            proxy.setFtpProxy(val);
        } else if (key.startsWith("chrome.cap.proxy.socks")) {
            String val = enginePro.getProperty(key);

            proxy.setSocksProxy(val);
        } else if (key.startsWith("chrome.cap.proxy.socks.username")) {
            String val = enginePro.getProperty(key);

            proxy.setSocksUsername(val);
        } else if (key.startsWith("chrome.cap.proxy.socks.password")) {
            String val = enginePro.getProperty(key);

            proxy.setSocksPassword(val);
        } else if (key.startsWith("chrome.binary")) {
            options.setBinary(enginePro.getProperty(key));
        }
    }

    if ("true".equals(enginePro.getProperty("chrome.cap.proxy.enable"))) {
        capability.setCapability("proxy", proxy);
    }
    capability.setCapability(ChromeOptions.CAPABILITY, options);

    engineCapMap.put(DRIVER_CHROME, capability);
}