How to change from call chrome selenium to other api with javascript excuted in openbullet(?) ? Someone know about it?



  • import org.junit.Assert;
    import org.openqa.selenium.firefox.FirefoxOptions;
    import org.openqa.selenium.remote.RemoteWebDriver;

    import org.json.JSONObject;
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.net.HttpURLConnection;
    import java.net.URL;

    public class BrowserProfile {
    public static void main(String[] args) throws Exception {
    BrowserProfile bp = new BrowserProfile();
    String profileId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";

        DesiredCapabilities dc = new DesiredCapabilities();
        RemoteWebDriver driver = new RemoteWebDriver(new URL(bp.startProfile(profileId)), dc);
        driver.get("https://google.com/");
        Assert.assertEquals("",driver.getTitle());
        driver.quit();
    }
    private String startProfile(String profileId) throws Exception {   
        String url = "http://127.0.0.1:35000/api/v1/profile/start?automation=true&profileId=" + profileId;
        URL obj = new URL(url);
        HttpURLConnection con = (HttpURLConnection) obj.openConnection();
        con.setRequestMethod("GET");
        BufferedReader in = new BufferedReader(
                new InputStreamReader(con.getInputStream()));
        String inputLine;
        StringBuffer response = new StringBuffer();
        while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
        }
        in.close();    
        JSONObject jsonResponse = new JSONObject(response.toString());
        return jsonResponse.getString("value");
    }
    

    }


Log in to reply