{"id":513,"date":"2023-02-07T09:20:36","date_gmt":"2023-02-07T01:20:36","guid":{"rendered":"https:\/\/www.xlogin.us\/help\/docs\/document\/api-automation\/selenium-browser-automation\/"},"modified":"2024-12-04T15:26:13","modified_gmt":"2024-12-04T07:26:13","slug":"selenium-browser-automation","status":"publish","type":"docs","link":"https:\/\/www.xlogin.us\/help\/docs\/api-automation\/selenium-browser-automation\/","title":{"rendered":"Selenium Browser Automation"},"content":{"rendered":"\n<p class=\"has-medium-font-size\">Browser automation allows you to automate tasks in XLogin's browser configuration file. From creating simple automated scripts to complex web crawlers, you can search, collect, and interact with web data.<\/p>\n\n\n\n<p class=\"has-medium-font-size\"><br><strong><a rel=\"noreferrer noopener\" href=\"https:\/\/xlogin.us\/\" data-type=\"URL\" data-id=\"https:\/\/xlogin.us\/\" target=\"_blank\">XLogin<\/a><\/strong> browser automation is based on Selenium WebDriver.<\/p>\n\n\n\n<p class=\"has-medium-font-size\"><br>Normally, if you run Selenium code, you must connect to the Chrome driver first and then set up the necessary functions. You don\u2019t need this step When using <strong><a href=\"https:\/\/xlogin.us\" data-type=\"URL\" data-id=\"https:\/\/xlogin.us\" target=\"_blank\" rel=\"noreferrer noopener\">XLogin<\/a><\/strong> with Selenium code. You will use the Remote Web Driver program to connect to the XLogin 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:25px\"><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 class=\"has-medium-font-size\"><br>The Selenium framework provides multiple languages that can be used together, so XLogin automation can also run on multiple coding languages. But at present, we only provide technical support for Java and Python.<\/p>\n\n\n\n<p style=\"font-size:25px\"><br><br><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">Using Selenium in XLogin<\/mark><\/strong><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><br>Define <strong><a href=\"https:\/\/xlogin.us\" data-type=\"URL\" data-id=\"https:\/\/xlogin.us\" target=\"_blank\" rel=\"noreferrer noopener\">XLogin <\/a><\/strong>port: To use Selenium automation, you need to define the software port in advance. Here is how to define the port:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"995\" height=\"693\" src=\"https:\/\/www.xlogin.us\/help\/wp-content\/uploads\/2023\/02\/4-6.png\" alt=\"\" class=\"wp-image-606\" srcset=\"https:\/\/www.xlogin.us\/help\/wp-content\/uploads\/2023\/02\/4-6.png 995w, https:\/\/www.xlogin.us\/help\/wp-content\/uploads\/2023\/02\/4-6-300x209.png 300w, https:\/\/www.xlogin.us\/help\/wp-content\/uploads\/2023\/02\/4-6-768x535.png 768w\" sizes=\"auto, (max-width: 995px) 100vw, 995px\" \/><\/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\"><br>Then, you can connect to XLogin through the defined port.<\/p>\n\n\n\n<p class=\"has-medium-font-size\"><br>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\"><br><small><em><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><\/em><\/small><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><br><strong>There are four types of agents:<\/strong><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><br><small><em><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">proxytype=http<\/mark><\/em><\/small><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><small><em><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">proxytype=http<\/mark><\/em><\/small><em><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">s<\/mark><\/em><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><small><em><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">proxytype=socks4<\/mark><\/em><\/small><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><small><em><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">proxytype=socks5<\/mark><\/em><\/small><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><br>The proxy username and password can be left blank.<\/p>\n\n\n\n<p><br><br><\/p>\n\n\n\n<p style=\"font-size:25px\"><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<p><br><br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><mark style=\"background-color:rgba(0, 0, 0, 0);color:#2961ee\" class=\"has-inline-color\">from<\/mark> selenium <mark style=\"background-color:rgba(0, 0, 0, 0);color:#2961ee\" class=\"has-inline-color\">import<\/mark> webdriver\n<mark style=\"background-color:rgba(0, 0, 0, 0);color:#2961ee\" class=\"has-inline-color\">from<\/mark> selenium.webdriver.chrome.options <mark style=\"background-color:rgba(0, 0, 0, 0);color:#2961ee\" class=\"has-inline-color\">import<\/mark> Options\n<mark style=\"background-color:rgba(0, 0, 0, 0);color:#2961ee\" class=\"has-inline-color\">import<\/mark> requests\n\nmla_profile_id = <mark style=\"background-color:rgba(0, 0, 0, 0);color:#eb9723\" class=\"has-inline-color\">'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'<\/mark>\nmla_url = <mark style=\"background-color:rgba(0, 0, 0, 0);color:#eb9723\" class=\"has-inline-color\">'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:#eb9723\" class=\"has-inline-color\">'ERROR'<\/mark>\n\nstatuscode=json&#91;<mark style=\"background-color:rgba(0, 0, 0, 0);color:#eb9723\" 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:#2961ee\" class=\"has-inline-color\">if<\/mark> errorcode==statuscode:\n    <mark style=\"background-color:rgba(0, 0, 0, 0);color:#2961ee\" class=\"has-inline-color\">print<\/mark>(json&#91;<mark style=\"background-color:rgba(0, 0, 0, 0);color:#eb9723\" 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:#2961ee\" class=\"has-inline-color\">print<\/mark>(json&#91;<mark style=\"background-color:rgba(0, 0, 0, 0);color:#eb9723\" 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:#eb9723\" class=\"has-inline-color\">\"debuggerAddress\"<\/mark>, json&#91;<mark style=\"background-color:rgba(0, 0, 0, 0);color:#eb9723\" class=\"has-inline-color\">'value'<\/mark>]&#91;7:])\nchrome_driver = r<mark style=\"background-color:rgba(0, 0, 0, 0);color:#eb9723\" class=\"has-inline-color\">\"chromedriver.exe\"<\/mark> \n<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">#https:\/\/down.xlogin.us\/92.0.4515.131.zip?swcfpc=1\n#download the chromedriver file and place it in the python directory<\/mark>\ndriver = webdriver.Chrome(chrome_driver, options=chrome_options)\n\ndriver.get(<mark style=\"background-color:rgba(0, 0, 0, 0);color:#eb9723\" class=\"has-inline-color\">'https:\/\/www.xlogin.us\/'<\/mark>)\nexecutor_url = driver.command_executor._url\nsession_id = driver.session_id\n<mark style=\"background-color:rgba(0, 0, 0, 0);color:#2961ee\" class=\"has-inline-color\">print<\/mark>(executor_url)\n<mark style=\"background-color:rgba(0, 0, 0, 0);color:#2961ee\" class=\"has-inline-color\">print<\/mark>(session_id)\n<mark style=\"background-color:rgba(0, 0, 0, 0);color:#2961ee\" class=\"has-inline-color\">print<\/mark>(<mark style=\"background-color:rgba(0, 0, 0, 0);color:#eb9723\" class=\"has-inline-color\">'ok it is done'<\/mark>)\n\ndriver.quit()<\/code><\/pre>\n\n\n\n<p><br><br><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f41919\" class=\"has-inline-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><\/p>\n\n\n\n<p><br><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:#eb9723\" 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:#f41919\" class=\"has-inline-color\">get<\/mark>(mla_url)\njson = resp.<mark style=\"background-color:rgba(0, 0, 0, 0);color:#f41919\" 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:#eb9723\" class=\"has-inline-color\">'ERROR'<\/mark>\n\nstatuscode=json&#91;<mark style=\"background-color:rgba(0, 0, 0, 0);color:#eb9723\" 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:#2961ee\" class=\"has-inline-color\">if<\/mark> errorcode==statuscode:\n    <mark style=\"background-color:rgba(0, 0, 0, 0);color:#f41919\" class=\"has-inline-color\">print<\/mark>(json&#91;<mark style=\"background-color:rgba(0, 0, 0, 0);color:#eb9723\" 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    <mark style=\"background-color:rgba(0, 0, 0, 0);color:#f41919\" 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:#f41919\" class=\"has-inline-color\">print<\/mark>(json&#91;<mark style=\"background-color:rgba(0, 0, 0, 0);color:#eb9723\" class=\"has-inline-color\">'value'<\/mark>])\n\nchrome_options = <mark style=\"background-color:rgba(0, 0, 0, 0);color:#f41919\" class=\"has-inline-color\">Options<\/mark>()\nchrome_options<mark style=\"background-color:rgba(0, 0, 0, 0);color:#f41919\" class=\"has-inline-color\">.add_experimental_option<\/mark>(<mark style=\"background-color:rgba(0, 0, 0, 0);color:#eb9723\" class=\"has-inline-color\">\"debuggerAddress\",<\/mark> json&#91;<mark style=\"background-color:rgba(0, 0, 0, 0);color:#eb9723\" class=\"has-inline-color\">'value'<\/mark>]&#91;7:])\n\nservice = <mark style=\"background-color:rgba(0, 0, 0, 0);color:#f41919\" class=\"has-inline-color\">ChromeService<\/mark>(executable_path=json&#91;<mark style=\"background-color:rgba(0, 0, 0, 0);color:#eb9723\" class=\"has-inline-color\">'chromedriver'<\/mark>])\n\ndriver = webdriver.<mark style=\"background-color:rgba(0, 0, 0, 0);color:#f41919\" class=\"has-inline-color\">Chrome<\/mark>( service=service ,options=chrome_options)\n\ndriver.<mark style=\"background-color:rgba(0, 0, 0, 0);color:#f41919\" class=\"has-inline-color\">get<\/mark>(<mark style=\"background-color:rgba(0, 0, 0, 0);color:#eb9723\" class=\"has-inline-color\">'https:\/\/www.xlogin.us\/'<\/mark>)\nexecutor_url = driver.command_executor._url\nsession_id = driver.session_id\n<mark style=\"background-color:rgba(0, 0, 0, 0);color:#f41919\" class=\"has-inline-color\">print<\/mark>(executor_url)\n<mark style=\"background-color:rgba(0, 0, 0, 0);color:#f41919\" class=\"has-inline-color\">print<\/mark>(session_id)\n<mark style=\"background-color:rgba(0, 0, 0, 0);color:#f41919\" class=\"has-inline-color\">print<\/mark>(<mark style=\"background-color:rgba(0, 0, 0, 0);color:#eb9723\" class=\"has-inline-color\">'ok it is done'<\/mark>)\n\n#driver.<mark style=\"background-color:rgba(0, 0, 0, 0);color:#f41919\" class=\"has-inline-color\">quit<\/mark>()\n\n<\/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><br><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f41919\" class=\"has-inline-color\">Selenium antidetect can be set in&nbsp;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><br><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Please pay attention to the Kernel version of the XLogin browser<\/strong><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><br><\/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><a href=\"https:\/\/down.xlogin.us\/92.0.4515.131.zip?swcfpc=1\">https:\/\/down.xlogin.us\/92.0.4515.131.zip?swcfpc=1<\/a><\/p>\n\n\n\n<p><br><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>If the Kernel version is 96, download this one:<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/down.xlogin.us\/96.0.4664.45.zip?swcfpc=1\">https:\/\/down.xlogin.us\/96.0.4664.45.zip?swcfpc=1<\/a><\/p>\n\n\n\n<p><br><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>All Kernels Download link:<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/www.xlogin.us\/help\/docs\/getting-started\/download-the-xlogin-kernel\/\">https:\/\/www.xlogin.us\/help\/docs\/getting-started\/download-the-xlogin-kernel\/<\/a><br><br><\/p>\n\n\n\n<p class=\"has-medium-font-size\">If the chromedriver version is not corresponding, it will cause failed automation.<\/p>\n\n\n\n<p class=\"has-medium-font-size\"><br>If you cannot close the browser, you can use&nbsp;<small><em><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><\/em><\/small>&nbsp;interface to close the browser process of the specified configuration.<\/p>\n\n\n\n<p class=\"has-medium-font-size\"><br>If you can only open the browser when running the code, but cannot open the website, <strong>you may copy and paste the chromedriver.exe to your python installation directory, or you select the mobile emulation mode<\/strong> which may cause this problem.<\/p>\n\n\n\n<p><br><br><\/p>\n\n\n\n<p><br><\/p>\n","protected":false},"featured_media":0,"parent":810,"menu_order":6,"comment_status":"closed","ping_status":"closed","template":"","doc_tag":[],"class_list":["post-513","docs","type-docs","status-publish","hentry"],"comment_count":0,"_links":{"self":[{"href":"https:\/\/www.xlogin.us\/help\/wp-json\/wp\/v2\/docs\/513","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xlogin.us\/help\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/www.xlogin.us\/help\/wp-json\/wp\/v2\/types\/docs"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xlogin.us\/help\/wp-json\/wp\/v2\/comments?post=513"}],"version-history":[{"count":27,"href":"https:\/\/www.xlogin.us\/help\/wp-json\/wp\/v2\/docs\/513\/revisions"}],"predecessor-version":[{"id":3080,"href":"https:\/\/www.xlogin.us\/help\/wp-json\/wp\/v2\/docs\/513\/revisions\/3080"}],"up":[{"embeddable":true,"href":"https:\/\/www.xlogin.us\/help\/wp-json\/wp\/v2\/docs\/810"}],"next":[{"title":"JAVA Uses Code for Using XLogin Automation API Interface to Launch Browser","link":"https:\/\/www.xlogin.us\/help\/docs\/api-automation\/java-code-to-launch-browser\/","href":"https:\/\/www.xlogin.us\/help\/wp-json\/wp\/v2\/docs\/524"}],"prev":[{"title":"Where can the Profile ID be Found?","link":"https:\/\/www.xlogin.us\/help\/docs\/api-automation\/where-can-the-profile-id-be-found\/","href":"https:\/\/www.xlogin.us\/help\/wp-json\/wp\/v2\/docs\/511"}],"wp:attachment":[{"href":"https:\/\/www.xlogin.us\/help\/wp-json\/wp\/v2\/media?parent=513"}],"wp:term":[{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/www.xlogin.us\/help\/wp-json\/wp\/v2\/doc_tag?post=513"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}