{"id":573,"date":"2022-11-18T16:13:32","date_gmt":"2022-11-18T08:13:32","guid":{"rendered":"https:\/\/vmlogin.us\/help\/?p=573"},"modified":"2023-05-18T16:00:22","modified_gmt":"2023-05-18T08:00:22","slug":"java-uses-code-for-using-vmlogin-automation-api-interface-to-launch-browser","status":"publish","type":"post","link":"https:\/\/www.vmlogin.us\/help\/api\/java-code.html","title":{"rendered":"JAVA Uses Code for Using VMLogin Automation API Interface to Launch Browser"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>package com.ruoyi.threed;\n\n\nimport com.alibaba.fastjson2.JSONObject;\nimport org.openqa.selenium.remote.DesiredCapabilities;\nimport org.openqa.selenium.remote.RemoteWebDriver;\nimport org.openqa.selenium.WebDriver;\nimport org.openqa.selenium.chrome.ChromeDriver;\nimport org.openqa.selenium.chrome.ChromeOptions;\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.net.HttpURLConnection;\nimport java.net.URL;\nimport java.util.Map;\n\npublic class BrowserProfile {\n    public static void main(String&#91;] args) throws Exception {\n        BrowserProfile bp = new BrowserProfile();\n\n        String profileId = \"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\";\n\n        String ss = bp.startProfile(profileId);\n        System.out.println(\"ss:\"+ss);\n\n\n        Map&lt;String,Object> _map =  JSONObject.parseObject( ss.toString(),Map.class);\n        String vaa = _map.get(\"value\").toString();\n        System.out.println(\"value()\"+vaa.toString());\n        URL url = new URL(vaa);\n        String  dizip =url.getAuthority().replace(\"http:\/\/\",\"\");\n        System.out.println(\"dizip:\"+dizip);\n\n        String drvstr = _map.get(\"chromedriver\").toString();\n\n        System.setProperty(\"webdriver.chrome.driver\",drvstr);\n       \n        ChromeOptions options = new ChromeOptions();\n        options.setExperimentalOption(\"debuggerAddress\",dizip);\n        WebDriver driver = new ChromeDriver(options);\n  \n\n        \/\/visit vmlogin\n        driver.navigate().to(\"http:\/\/www.vmlogin.us\");\n        System.out.println(driver.getTitle());\n        driver.quit();\n    }\n\n    private String startProfile(String profileId) throws Exception {\n\n  \n        String url = \"http:\/\/127.0.0.1:35000\/api\/v1\/profile\/start?skiplock=true&amp;profileId=\" + profileId;\n     \n        URL obj = new URL(url);\n        HttpURLConnection con = (HttpURLConnection) obj.openConnection();\n\n        con.setRequestMethod(\"GET\");\n\n        BufferedReader in = new BufferedReader(\n                new InputStreamReader(con.getInputStream()));\n        String inputLine;\n        StringBuffer response = new StringBuffer();\n\n        while ((inputLine = in.readLine()) != null) {\n            response.append(inputLine);\n        }\n        in.close();\n        System.out.println(\"response.toString()\"+response.toString());\n    \n        Thread.sleep(3000);\n        return response.toString();\n    }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-573","post","type-post","status-publish","format-standard","hentry","category-api"],"_links":{"self":[{"href":"https:\/\/www.vmlogin.us\/help\/wp-json\/wp\/v2\/posts\/573","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vmlogin.us\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.vmlogin.us\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.vmlogin.us\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vmlogin.us\/help\/wp-json\/wp\/v2\/comments?post=573"}],"version-history":[{"count":22,"href":"https:\/\/www.vmlogin.us\/help\/wp-json\/wp\/v2\/posts\/573\/revisions"}],"predecessor-version":[{"id":2814,"href":"https:\/\/www.vmlogin.us\/help\/wp-json\/wp\/v2\/posts\/573\/revisions\/2814"}],"wp:attachment":[{"href":"https:\/\/www.vmlogin.us\/help\/wp-json\/wp\/v2\/media?parent=573"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vmlogin.us\/help\/wp-json\/wp\/v2\/categories?post=573"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vmlogin.us\/help\/wp-json\/wp\/v2\/tags?post=573"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}