{"id":1336,"date":"2021-03-24T15:12:12","date_gmt":"2021-03-24T12:12:12","guid":{"rendered":"https:\/\/www.etemkeskin.com\/?p=1336"},"modified":"2021-03-25T21:14:14","modified_gmt":"2021-03-25T18:14:14","slug":"how-to-keep-open-chrome-browser-when-using-selenium","status":"publish","type":"post","link":"https:\/\/www.etemkeskin.com\/index.php\/2021\/03\/24\/how-to-keep-open-chrome-browser-when-using-selenium\/","title":{"rendered":"How to Keep Chrome Browser Open When Using Selenium"},"content":{"rendered":"\n<p>With <strong>Selenium<\/strong>, we can automate the tests of our web applications. We prepare a test case to test our web application. This test scenario can take several steps.<\/p>\n\n\n\n<p>While conducting our tests, the test may not be able to pass to another without passing one step, as required by the scenario. If our browser is not always open, when we come across a step where our test fails, our test is terminated and it may be necessary to start the test again from the first step. To solve this situation and to use our time more efficiently, we would like to keep our browser open all the time.<\/p>\n\n\n\n<p>In this post, I will explain how we can keep our web browser open for our tests.<\/p>\n\n\n\n<p>We will open our browser in <strong>debugging mode<\/strong> in order to keep our <strong>Chrome Browser<\/strong> open all the time. For detailed information on how to run Chrome in debugging mode, you can check chrome&#8217;s developer documentation at the link below.<\/p>\n\n\n\n<p><a href=\"https:\/\/chromedevtools.github.io\/devtools-protocol\/\">https:\/\/chromedevtools.github.io\/devtools-protocol\/<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"928\" height=\"240\" src=\"https:\/\/www.etemkeskin.com\/wp-content\/uploads\/2021\/03\/image-3.png\" alt=\"\" class=\"wp-image-1351\"\/><figcaption>Chrome Devtools Documantation<\/figcaption><\/figure>\n\n\n\n<h4>Opening Chrome Browser in Debugging Mode<\/h4>\n\n\n\n<p>We create a folder named <strong>chromedata<\/strong> where user data will be saved in the folder where <strong>chromedriver.exe<\/strong> is located. The name of the file can be any name.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"792\" height=\"123\" src=\"https:\/\/www.etemkeskin.com\/wp-content\/uploads\/2021\/03\/image-4.png\" alt=\"\" class=\"wp-image-1353\"\/><figcaption>Folder Structure<\/figcaption><\/figure>\n\n\n\n<p>In order to open Chrome Browser in debugging mode, we first open our terminal screen and run the following command to reach <strong>chrome.exe<\/strong> file in the folder where chrome is installed. This path may be different on your computer.<\/p>\n\n\n\n<p><code>cd C:\\Program Files\\Google\\Chrome\\Application<\/code><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"651\" height=\"302\" src=\"https:\/\/www.etemkeskin.com\/wp-content\/uploads\/2021\/03\/image.png\" alt=\"\" class=\"wp-image-1341\"\/><figcaption>chrome.exe folder<\/figcaption><\/figure>\n\n\n\n<p>Then we run the commands below.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>chrome.exe --remote-debugging-port=9222 chrome.exe --user-data-dir=C:\\Users\\etem\\Desktop\\myscript\\chromedata<\/code><\/pre>\n\n\n\n<p>If we run these commands in the <strong>terminal screen<\/strong>, the browser opens as follows. We will reach this browser at port <strong>9222<\/strong>.<a href=\"\"><\/a><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1440\" height=\"239\" src=\"https:\/\/www.etemkeskin.com\/wp-content\/uploads\/2021\/03\/image-1.png\" alt=\"\" class=\"wp-image-1343\"\/><figcaption>Opened Chrome Web Browser<\/figcaption><\/figure>\n\n\n\n<p>In the python code block below, I have shown how to use chrome driver.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;showPanel&quot;:false,&quot;language&quot;:&quot;Python&quot;,&quot;modeName&quot;:&quot;python&quot;}\">from selenium import webdriver\nimport time\nfrom selenium.webdriver.common.keys import Keys\nfrom selenium.webdriver.chrome.options import Options\n\ndef crawl_website(search_key_send):\n    chrome_options = Options()\n    chrome_options.debugger_address=&quot;localhost:9222&quot;\n    \n    browser =webdriver.Chrome(executable_path=r&quot;C:\\Users\\etem\\Desktop\\myscript\\chromedriver.exe&quot;,options=chrome_options)\n\n    browser.get(&quot;https:\/\/www.etemkeskin.com\/&quot;)<\/pre><\/div>\n\n\n\n<p>Success &#8230;<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>With Selenium, we can automate the tests of our web applications. We prepare a test case to test our web application. This test scenario can take several steps. While conducting our tests, the test may not be able to pass to another without passing one step, as required by the scenario. If our browser is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1,4],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v16.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Keep Chrome Browser Open When Using Selenium - blog website<\/title>\n<meta name=\"description\" content=\"With Selenium, we can automate the tests of our web applications. We prepare a test case to test our web application. This test scenario can take several steps. While conducting our tests, the test may not be able to pass to another without passing one step, as required by the scenario. If our browser is not always open, when we come across a step where our test fails, our test is terminated and it may be necessary to start the test again from the first step. To solve this situation and to use our time more efficiently, we would like to keep our browser open all the time.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.etemkeskin.com\/index.php\/2021\/03\/24\/how-to-keep-open-chrome-browser-when-using-selenium\/\" \/>\n<meta property=\"og:locale\" content=\"tr_TR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Keep Chrome Browser Open When Using Selenium - blog website\" \/>\n<meta property=\"og:description\" content=\"With Selenium, we can automate the tests of our web applications. We prepare a test case to test our web application. This test scenario can take several steps. While conducting our tests, the test may not be able to pass to another without passing one step, as required by the scenario. If our browser is not always open, when we come across a step where our test fails, our test is terminated and it may be necessary to start the test again from the first step. To solve this situation and to use our time more efficiently, we would like to keep our browser open all the time.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.etemkeskin.com\/index.php\/2021\/03\/24\/how-to-keep-open-chrome-browser-when-using-selenium\/\" \/>\n<meta property=\"og:site_name\" content=\"blog website\" \/>\n<meta property=\"article:published_time\" content=\"2021-03-24T12:12:12+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-03-25T18:14:14+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.etemkeskin.com\/wp-content\/uploads\/2021\/03\/image-3.png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Tahmini okuma s\u00fcresi\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 dakika\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.etemkeskin.com\/#website\",\"url\":\"https:\/\/www.etemkeskin.com\/\",\"name\":\"blog website\",\"description\":\"Etem KESK\\u0130N\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/www.etemkeskin.com\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"tr\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.etemkeskin.com\/index.php\/2021\/03\/24\/how-to-keep-open-chrome-browser-when-using-selenium\/#primaryimage\",\"inLanguage\":\"tr\",\"url\":\"https:\/\/www.etemkeskin.com\/wp-content\/uploads\/2021\/03\/image-3.png\",\"contentUrl\":\"https:\/\/www.etemkeskin.com\/wp-content\/uploads\/2021\/03\/image-3.png\",\"width\":928,\"height\":240},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.etemkeskin.com\/index.php\/2021\/03\/24\/how-to-keep-open-chrome-browser-when-using-selenium\/#webpage\",\"url\":\"https:\/\/www.etemkeskin.com\/index.php\/2021\/03\/24\/how-to-keep-open-chrome-browser-when-using-selenium\/\",\"name\":\"How to Keep Chrome Browser Open When Using Selenium - blog website\",\"isPartOf\":{\"@id\":\"https:\/\/www.etemkeskin.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.etemkeskin.com\/index.php\/2021\/03\/24\/how-to-keep-open-chrome-browser-when-using-selenium\/#primaryimage\"},\"datePublished\":\"2021-03-24T12:12:12+00:00\",\"dateModified\":\"2021-03-25T18:14:14+00:00\",\"author\":{\"@id\":\"https:\/\/www.etemkeskin.com\/#\/schema\/person\/dcbc30282861ce578b96a79ce8789629\"},\"description\":\"With Selenium, we can automate the tests of our web applications. We prepare a test case to test our web application. This test scenario can take several steps. While conducting our tests, the test may not be able to pass to another without passing one step, as required by the scenario. If our browser is not always open, when we come across a step where our test fails, our test is terminated and it may be necessary to start the test again from the first step. To solve this situation and to use our time more efficiently, we would like to keep our browser open all the time.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.etemkeskin.com\/index.php\/2021\/03\/24\/how-to-keep-open-chrome-browser-when-using-selenium\/#breadcrumb\"},\"inLanguage\":\"tr\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.etemkeskin.com\/index.php\/2021\/03\/24\/how-to-keep-open-chrome-browser-when-using-selenium\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.etemkeskin.com\/index.php\/2021\/03\/24\/how-to-keep-open-chrome-browser-when-using-selenium\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Ana sayfa\",\"item\":\"https:\/\/www.etemkeskin.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Keep Chrome Browser Open When Using Selenium\"}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.etemkeskin.com\/#\/schema\/person\/dcbc30282861ce578b96a79ce8789629\",\"name\":\"etemkeskin\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.etemkeskin.com\/#personlogo\",\"inLanguage\":\"tr\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/6af0148b790691ed24ae245fb3dc773b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/6af0148b790691ed24ae245fb3dc773b?s=96&d=mm&r=g\",\"caption\":\"etemkeskin\"},\"url\":\"https:\/\/www.etemkeskin.com\/index.php\/author\/etemkeskinyahoo-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/www.etemkeskin.com\/index.php\/wp-json\/wp\/v2\/posts\/1336"}],"collection":[{"href":"https:\/\/www.etemkeskin.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.etemkeskin.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.etemkeskin.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.etemkeskin.com\/index.php\/wp-json\/wp\/v2\/comments?post=1336"}],"version-history":[{"count":42,"href":"https:\/\/www.etemkeskin.com\/index.php\/wp-json\/wp\/v2\/posts\/1336\/revisions"}],"predecessor-version":[{"id":1388,"href":"https:\/\/www.etemkeskin.com\/index.php\/wp-json\/wp\/v2\/posts\/1336\/revisions\/1388"}],"wp:attachment":[{"href":"https:\/\/www.etemkeskin.com\/index.php\/wp-json\/wp\/v2\/media?parent=1336"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.etemkeskin.com\/index.php\/wp-json\/wp\/v2\/categories?post=1336"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.etemkeskin.com\/index.php\/wp-json\/wp\/v2\/tags?post=1336"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}