{"id":20171,"date":"2015-05-26T17:31:40","date_gmt":"2015-05-26T12:01:40","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=20171"},"modified":"2015-05-28T16:19:52","modified_gmt":"2015-05-28T10:49:52","slug":"handing-browser-alert-box-using-selenium-web-driver","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/handing-browser-alert-box-using-selenium-web-driver\/","title":{"rendered":"Handing Browser Alert Box Using Selenium Web Driver"},"content":{"rendered":"<p>Recently while working on selenium I have come across in a situation where browser dialog box are the show stopper to validate &#8216;Login\/Registration\/Forgot Password etc.&#8217; modules, though we are considering such cases as design issues.<\/p>\n<p>However we need to deal with it to learn something new, fortunately I have got the solution to handle browser alerts.<\/p>\n<p>Scenario &#8211; Assuming browser dialog box having only one button i.e. OK.<\/p>\n<p>[java]<br \/>\n{<\/p>\n<p>{<\/p>\n<p>&lt;em&gt;WebDriver driver = new FirefoxDriver();<br \/>\n&lt;em&gt; driver.manage().window().maximize();<br \/>\n&lt;em&gt; driver.get(&quot;Site URL (Eg: www.google.com&quot;);<br \/>\n&lt;em&gt;driver.findElement(By.id(&quot;Enter you register id or any element&quot;)).click();<\/p>\n<p>&lt;em&gt;driver.findElement(By.id(&quot;could be user name id&quot;)).sendKeys(&quot;XYZ&quot;);<\/p>\n<p>&lt;em&gt;driver.findElement(By.id(&quot;Submit&quot;)).click();<\/p>\n<p>&amp;nbsp;<\/p>\n<p>&lt;em&gt;Alert alert=driver.switchTo().alert();<br \/>\n&lt;em&gt; System.out.println(alert.getText()); [This is only for output check]<br \/>\n&lt;em&gt; alert.accept();<\/p>\n<p>}<\/p>\n<p>}<br \/>\n[\/java]<\/p>\n<p>To click on &#8216;Cancel&#8217; button you can use &#8211; driver.dismiss();<\/p>\n<p>Output &#8211; It will give you the exact text showing on your browser dialog box in console output.<\/p>\n<p>Hope it will help you, Happy Learning!!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently while working on selenium I have come across in a situation where browser dialog box are the show stopper to validate &#8216;Login\/Registration\/Forgot Password etc.&#8217; modules, though we are considering such cases as design issues. However we need to deal with it to learn something new, fortunately I have got the solution to handle browser [&hellip;]<\/p>\n","protected":false},"author":199,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":3},"categories":[1818,7,446,1,1816],"tags":[1561,14,25,1562,1563],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/20171"}],"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\/199"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=20171"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/20171\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=20171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=20171"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=20171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}