{"id":32163,"date":"2016-02-04T12:38:03","date_gmt":"2016-02-04T07:08:03","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=32163"},"modified":"2016-12-19T15:37:41","modified_gmt":"2016-12-19T10:07:41","slug":"easy-approach-to-handle-authentication-window-in-selenium-webdriver","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/easy-approach-to-handle-authentication-window-in-selenium-webdriver\/","title":{"rendered":"Easy approach to handle authentication window in selenium webdriver"},"content":{"rendered":"<p>Before we get started, on how to handle authentication window in Selenium WebDriver. Let\u2019s discuss what authentication window is &amp; why it is used in applications?<\/p>\n<p><strong>What is Authentication Window? <\/strong><\/p>\n<p>Authentication is a process which is required to access some applications in which HTTP authentication is used for security purpose. These are server side validations which ask for authentication beforehand user can access an application. Also, known as basic authentication in `web applications where the browser window is used to get user credentials. The handling of pop up window came into the picture because of security and minimizing the unauthorized users in the application.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-32166\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/02\/POP-UP.png\" alt=\"POP UP\" width=\"407\" height=\"241\" \/><\/p>\n<p>While <a title=\"automation testing services\" href=\"http:\/\/www.tothenew.com\/testing\/automated-independent-manual-testing\">automating an application testing<\/a> through selenium, this issue is generally faced by some of us. I have checked this in many other websites talking about handling pop up window using the installation of AutoIt Tool, Add-ons like AuthAuth etc.<\/p>\n<p><strong>Why is this issue encountered?<\/strong><\/p>\n<p>Let\u2019s discuss more closely why this issue is encountered? While running the automated script on the website it locates the elements using the \u2018FindElement\u2019 method. Since authentication protected applications restricts the user to access the web elements. We simply append username and password in the web application URL, so that it allows the script to access locators.<\/p>\n<p><strong>What&#8217;s the solution?<\/strong><\/p>\n<p>Here is a simple approach to overcome this issue. This can be easily handled using the piece of code below:<\/p>\n<p>baseUrl=&#8221;http:\/\/&#8221; + username + &#8220;:&#8221; + password + &#8220;@&#8221; + url;<\/p>\n<p>driver.get(baseUrl + &#8220;\/&#8221;);<\/p>\n<p>Using code above we are providing credentials in URL which will add username &amp; password in URL ), while running the script it will bypass the authentication window successfully<\/p>\n<p><strong>\u00a0<\/strong><strong>Refer syntax in how it is done just after browser is launched:\u00a0<\/strong><\/p>\n<p>WebDriver driver = <strong>new<\/strong> FirefoxDriver();<\/p>\n<p>String baseUrl=&#8221;http:\/\/&#8221; + &#8220;USERNAME&#8221; + &#8220;:&#8221; + &#8220;PASSWORD&#8221; + &#8220;@&#8221; + &#8220;xyz.com&#8221;;<\/p>\n<p>driver.get(baseUrl + &#8220;\/&#8221;);<\/p>\n<p>Hope the above solution works. Please let me know if you have any queries\/ additions in the comment box below.<\/p>\n<p><strong><em>Happy Testing!! <\/em><\/strong><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Before we get started, on how to handle authentication window in Selenium WebDriver. Let\u2019s discuss what authentication window is &amp; why it is used in applications? What is Authentication Window? Authentication is a process which is required to access some applications in which HTTP authentication is used for security purpose. These are server side validations [&hellip;]<\/p>\n","protected":false},"author":132,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":54},"categories":[1818,1816],"tags":[1221,1853,25,1562],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/32163"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/132"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=32163"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/32163\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=32163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=32163"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=32163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}