{"id":568,"date":"2022-11-18T11:44:07","date_gmt":"2022-11-18T03:44:07","guid":{"rendered":"https:\/\/vmlogin.us\/help\/?p=568"},"modified":"2024-04-18T15:07:53","modified_gmt":"2024-04-18T07:07:53","slug":"selenium-browser-automation","status":"publish","type":"post","link":"https:\/\/www.vmlogin.us\/help\/api\/selenium.html","title":{"rendered":"Selenium Browser Automation"},"content":{"rendered":"\n<p class=\"has-medium-font-size\">Browser automation allows you to automate tasks in VMLogin's browser configuration file. From creating simple automated scripts to complex web crawlers, you can search\u3001collect and interact with web data.<\/p>\n\n\n\n<p class=\"has-medium-font-size\"><a rel=\"noreferrer noopener\" href=\"https:\/\/www.vmlogin.us\" data-type=\"URL\" data-id=\"https:\/\/www.vmlogin.us\" target=\"_blank\"><strong>VMLogin<\/strong> <\/a>browser automation is based on<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\"> <\/mark><strong>Selenium WebDriver.<\/strong><\/p>\n\n\n\n<p class=\"has-medium-font-size\">Normally, if you run Selenium code, you need to connect to the Chrome driver first and then set up the functions you need. You don\u2019t need this step When using<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\"> <\/mark>VMLogin with Selenium code. You will use the Remote Web Driver program to connect to the Vmlogin application or a browser configuration file through a local port, set up the required functions, and execute Selenium commands in a predefined browser configuration file.<\/p>\n\n\n\n<p style=\"font-size:22px\"><br><br><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">Languages<\/mark><\/strong><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"has-medium-font-size\">The Selenium framework provides <strong>multiple languages<\/strong> that can be used together, so VMLogin automation can also run on multiple coding languages. <strong>But at present, we only provide technical support for Java and Python.<\/strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\"><br><\/mark><br><\/p>\n\n\n\n<p style=\"font-size:22px\"><br><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">Using Selenium in VMLogin<\/mark><\/strong><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"has-medium-font-size\">Define VMLogin port<\/p>\n\n\n\n<p class=\"has-medium-font-size\">You need to define the software port in advance to use <strong>Selenium automation<\/strong>. Here is how to define the port:<br><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"993\" height=\"691\" src=\"https:\/\/www.vmlogin.us\/help\/wp-content\/uploads\/2023\/02\/en-2-1.png\" alt=\"\" class=\"wp-image-2491\" srcset=\"https:\/\/www.vmlogin.us\/help\/wp-content\/uploads\/2023\/02\/en-2-1.png 993w, https:\/\/www.vmlogin.us\/help\/wp-content\/uploads\/2023\/02\/en-2-1-300x209.png 300w, https:\/\/www.vmlogin.us\/help\/wp-content\/uploads\/2023\/02\/en-2-1-768x534.png 768w\" sizes=\"auto, (max-width: 993px) 100vw, 993px\" \/><\/figure>\n\n\n\n<p class=\"has-medium-font-size\">In <strong>\"My Account\"<\/strong>, turn on the browser automation setting, and set the usable port in the listening port. The default value is 35000, You can also set an access password.<\/p>\n\n\n\n<p class=\"has-medium-font-size\">Then, you can connect to VMLogin through the defined port.<\/p>\n\n\n\n<p class=\"has-medium-font-size\">The interface can also pass in proxy server information. If the incoming proxy information will overwrite the proxy information in the configuration file, this overwriting is temporary and will not modify the configuration file. It is only valid for the automation interface:<\/p>\n\n\n\n<p class=\"has-medium-font-size\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">http:\/\/127.0.0.1:35000\/api\/v1\/profile\/start?skiplock=true&amp;profileId=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&amp;proxytype=socks5&amp;proxyserver=ip&amp;proxyport=1080&amp;proxyusername=&amp;proxypassword=<\/mark><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>There are fiour types of agents:<\/strong><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">proxytype=socks5<\/mark><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">proxytype=socks4<\/mark><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">proxytype=http<\/mark><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">proxytype=https<\/mark><\/p>\n\n\n\n<p class=\"has-medium-font-size\">The proxy username and password can be left blank.<\/p>\n\n\n\n<p style=\"font-size:22px\"><br><br><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">Python Case: (After installing Python, use cmd first to enter the Python\\Scripts directory, then run pip install selenium and pip install requests):<\/mark><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\n<mark style=\"background-color:rgba(0, 0, 0, 0);color:#0a0dd2\" class=\"has-inline-color\">from<\/mark> selenium <mark style=\"background-color:rgba(0, 0, 0, 0);color:#0a0dd2\" class=\"has-inline-color\">import <\/mark>webdriver\n<mark style=\"background-color:rgba(0, 0, 0, 0);color:#0a0dd2\" class=\"has-inline-color\">from<\/mark> selenium.webdriver.chrome.options <mark style=\"background-color:rgba(0, 0, 0, 0);color:#0a0dd2\" class=\"has-inline-color\">import<\/mark> Options\n<mark style=\"background-color:rgba(0, 0, 0, 0);color:#0a0dd2\" class=\"has-inline-color\">import<\/mark> requests\n\nmla_profile_id = <mark style=\"background-color:rgba(0, 0, 0, 0);color:#a17f08\" class=\"has-inline-color\">'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'\nmla_url = 'http:\/\/127.0.0.1:35000\/api\/v1\/profile\/start?skiplock=true&amp;profileId='+mla_profile_id<\/mark>\n\nresp = requests.get(mla_url)\njson = resp.json()\n\n<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">#Determine the return status of json. If it's ERROR, terminate the process and prompt an error message.<\/mark>\nerrorcode=<mark style=\"background-color:rgba(0, 0, 0, 0);color:#a17f08\" class=\"has-inline-color\">'ERROR'<\/mark>\n\nstatuscode=json<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-black-color\">&#91;<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#a17f08\" class=\"has-inline-color\">'status'<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-black-color\">]<\/mark><strong> <\/strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">#json return status<\/mark>\n\n<mark style=\"background-color:rgba(0, 0, 0, 0);color:#0a0dd2\" class=\"has-inline-color\">if<\/mark> errorcode==statuscode:\n    <mark style=\"background-color:rgba(0, 0, 0, 0);color:#0a0dd2\" class=\"has-inline-color\">print<\/mark>(json&#91;<mark style=\"background-color:rgba(0, 0, 0, 0);color:#a17f08\" class=\"has-inline-color\">'value'<\/mark>]) <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">#print the error information<\/mark>\n    quit() <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">#terminate the program<\/mark>\n    \n<mark style=\"background-color:rgba(0, 0, 0, 0);color:#0a0dd2\" class=\"has-inline-color\">print<\/mark>(json&#91;<mark style=\"background-color:rgba(0, 0, 0, 0);color:#a17f08\" class=\"has-inline-color\">'value'<\/mark>])\n\nchrome_options = Options()\nchrome_options.add_experimental_option(<mark style=\"background-color:rgba(0, 0, 0, 0);color:#a17f08\" class=\"has-inline-color\">\"debuggerAddress\"<\/mark>, json&#91;<mark style=\"background-color:rgba(0, 0, 0, 0);color:#a17f08\" class=\"has-inline-color\">'value'<\/mark>]&#91;7:])\nchrome_driver = r<mark style=\"background-color:rgba(0, 0, 0, 0);color:#a17f08\" class=\"has-inline-color\">\"chromedriver.exe\"<\/mark> \n#http:\/\/chromedriver.storage.googleapis.com\/92.0.4515.107\/chromedriver_win32.zip\n<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">#download the chromedriver file and place it in the python directory\ndriver = webdriver.Chrome(chrome_driver, options=chrome_options)<\/mark>\n\ndriver.get(<mark style=\"background-color:rgba(0, 0, 0, 0);color:#a17f08\" class=\"has-inline-color\">'https:\/\/www.bing.com\/'<\/mark>)\nexecutor_url = driver.command_executor._url\nsession_id = driver.session_id\n<mark style=\"background-color:rgba(0, 0, 0, 0);color:#0a0dd2\" class=\"has-inline-color\">print<\/mark>(executor_url)\n<mark style=\"background-color:rgba(0, 0, 0, 0);color:#0a0dd2\" class=\"has-inline-color\">print<\/mark>(session_id)\n<mark style=\"background-color:rgba(0, 0, 0, 0);color:#0a0dd2\" class=\"has-inline-color\">print<\/mark>(<mark style=\"background-color:rgba(0, 0, 0, 0);color:#a17f08\" class=\"has-inline-color\">'ok it is done'<\/mark>)\n\ndriver.quit()<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><br><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">Python Case: (The following code is required for using selenium version 4, while the previous code will cause an error in selenium version 4.)<\/mark><\/strong><br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from selenium import webdriver\nfrom selenium.webdriver.chrome.options import Options\nimport requests\nfrom selenium.webdriver.chrome.service import Service as ChromeService\nfrom webdriver_manager.chrome import ChromeDriverManager\n\n\nmla_profile_id =<mark style=\"background-color:rgba(0, 0, 0, 0);color:#a17f08\" class=\"has-inline-color\"> 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'\nmla_url = 'http:\/\/127.0.0.1:35000\/api\/v1\/profile\/start?skiplock=true&amp;profileId='+mla_profile_id<\/mark>\n\nresp = requests.<mark style=\"background-color:rgba(0, 0, 0, 0);color:#f20202\" class=\"has-inline-color\">get<\/mark>(mla_url)\njson = resp.<mark style=\"background-color:rgba(0, 0, 0, 0);color:#f20202\" class=\"has-inline-color\">json<\/mark>()\n\n\n<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">#Determine the return status of json. If it's ERROR, terminate the process and prompt an error message.<\/mark>\nerrorcode=<mark style=\"background-color:rgba(0, 0, 0, 0);color:#a17f08\" class=\"has-inline-color\">'ERROR'<\/mark>\n\nstatuscode=json&#91;<mark style=\"background-color:rgba(0, 0, 0, 0);color:#a17f08\" class=\"has-inline-color\">'status'<\/mark>] <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">#json return status<\/mark>\n\n<mark style=\"background-color:rgba(0, 0, 0, 0);color:#0a0dd2\" class=\"has-inline-color\">if<\/mark> errorcode==statuscode:\n    <mark style=\"background-color:rgba(0, 0, 0, 0);color:#f20202\" class=\"has-inline-color\">print<\/mark>(json&#91;<mark style=\"background-color:rgba(0, 0, 0, 0);color:#a17f08\" class=\"has-inline-color\">'value'<\/mark>])<strong> <\/strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">#print the error information<\/mark>\n   <mark style=\"background-color:rgba(0, 0, 0, 0);color:#f20202\" class=\"has-inline-color\"> quit<\/mark>()<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">#terminate the program<\/mark>\n    \n<mark style=\"background-color:rgba(0, 0, 0, 0);color:#f20202\" class=\"has-inline-color\">print<\/mark>(json&#91;<mark style=\"background-color:rgba(0, 0, 0, 0);color:#a17f08\" class=\"has-inline-color\">'value'<\/mark>])\n\nchrome_options = <mark style=\"background-color:rgba(0, 0, 0, 0);color:#f20202\" class=\"has-inline-color\">Options<\/mark>()\nchrome_options<mark style=\"background-color:rgba(0, 0, 0, 0);color:#f20202\" class=\"has-inline-color\">.add_experimental_option<\/mark>(<mark style=\"background-color:rgba(0, 0, 0, 0);color:#a17f08\" class=\"has-inline-color\">\"debuggerAddress\"<\/mark>, json&#91;<mark style=\"background-color:rgba(0, 0, 0, 0);color:#a17f08\" class=\"has-inline-color\">'value'<\/mark>]&#91;7:])\n\nservice = <mark style=\"background-color:rgba(0, 0, 0, 0);color:#f20202\" class=\"has-inline-color\">ChromeService<\/mark>(executable_path=json&#91;<mark style=\"background-color:rgba(0, 0, 0, 0);color:#a17f08\" class=\"has-inline-color\">'chromedriver'<\/mark>])\n\ndriver = webdriver.<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\">C<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f20202\" class=\"has-inline-color\">hrome<\/mark>( service=service ,options=chrome_options)\n\ndriver.<mark style=\"background-color:rgba(0, 0, 0, 0);color:#f20202\" class=\"has-inline-color\">get<\/mark>(<mark style=\"background-color:rgba(0, 0, 0, 0);color:#a17f08\" class=\"has-inline-color\">'https:\/\/www.bing.com\/'<\/mark>)\nexecutor_url = driver.command_executor._url\nsession_id = driver.session_id\n<mark style=\"background-color:rgba(0, 0, 0, 0);color:#f20202\" class=\"has-inline-color\">print<\/mark>(executor_url)\n<mark style=\"background-color:rgba(0, 0, 0, 0);color:#f20202\" class=\"has-inline-color\">print<\/mark>(session_id)\n<mark style=\"background-color:rgba(0, 0, 0, 0);color:#f20202\" class=\"has-inline-color\">print<\/mark>(<mark style=\"background-color:rgba(0, 0, 0, 0);color:#a17f08\" class=\"has-inline-color\">'ok it is done'<\/mark>)\n\n#driver.<mark style=\"background-color:rgba(0, 0, 0, 0);color:#f20202\" class=\"has-inline-color\">quit<\/mark>()<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\">The chromedriver file is available in each kernel installation directory, and the API to start the browser interface \/api\/v1\/profile\/start will also return the full path location of the chromedriver file.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">Selenium antidetect can be set in<\/mark><\/strong><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\"> Browser profile settings -&gt; Other Configurations -&gt; Customize Launch Browser Parameters to include \"--disable-blink-features=AutomationControlled\", which will have a certain effect.<\/mark><\/strong><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Please pay attention to the kernel version of the VMLogin browser<\/strong><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong> If it is 79, download this one:<\/strong><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">http:\/\/chromedriver.storage.googleapis.com\/79.0.3945.36\/chromedriver_win32.zip<\/mark><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>If the kernel version is 86, download this one:<\/strong><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">http:\/\/chromedriver.storage.googleapis.com\/86.0.4240.22\/chromedriver_win32.zip<\/mark><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>If the kernel version is 90, download this one:<\/strong><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">http:\/\/chromedriver.storage.googleapis.com\/90.0.4430.24\/chromedriver_win32.zip<\/mark><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>If the kernel version is 92, download this one:<\/strong><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">http:\/\/chromedriver.storage.googleapis.com\/92.0.4515.107\/chromedriver_win32.zip<\/mark><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><br><\/p>\n\n\n\n<p class=\"has-medium-font-size\">If the chromedriver version is not corresponding, it will cause failed automation.<br><br>If you cannot close the browser, you can use&nbsp;<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">http:\/\/127.0.0.1:35000\/api\/v1\/profile\/stop?profileId=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx<\/mark>&nbsp;interface to close the browser process of the specified configuration.<br><br>If you can only open the browser when running the code, but cannot open the website, <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">you may copy and paste the chromedriver.exe to your python installation directory<\/mark>, or you select the mobile emulation mode which may cause this problem.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Browser automation allows you to automate tasks in VMLo [&hellip;]<\/p>\n","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-568","post","type-post","status-publish","format-standard","hentry","category-api"],"_links":{"self":[{"href":"https:\/\/www.vmlogin.us\/help\/wp-json\/wp\/v2\/posts\/568","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=568"}],"version-history":[{"count":31,"href":"https:\/\/www.vmlogin.us\/help\/wp-json\/wp\/v2\/posts\/568\/revisions"}],"predecessor-version":[{"id":3797,"href":"https:\/\/www.vmlogin.us\/help\/wp-json\/wp\/v2\/posts\/568\/revisions\/3797"}],"wp:attachment":[{"href":"https:\/\/www.vmlogin.us\/help\/wp-json\/wp\/v2\/media?parent=568"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vmlogin.us\/help\/wp-json\/wp\/v2\/categories?post=568"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vmlogin.us\/help\/wp-json\/wp\/v2\/tags?post=568"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}