From: hai <mah...@es...> - 2014-12-19 05:23:05
|
Hi , Thanks for your reply. *You have some kind of web application that is available by an HTTPS URL - correct? Ist this app public available on the internet? * Yes application runs on https url but not available over internet. *If you click on a button, the application opens another window (in your words a popup window) - correct? * Yes *Is it a new tab in the browser or a dedicated browser window or a dialog window or an alert window?* Not its not a new tab in browser. Its an dialog box and not an alert. Let's me post my code <code> import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.gargoylesoftware.htmlunit.html.HtmlForm; import com.gargoylesoftware.htmlunit.html.HtmlButton; import com.gargoylesoftware.htmlunit.html.HtmlButtonInput; import com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput; import com.gargoylesoftware.htmlunit.html.HtmlAnchor; import com.gargoylesoftware.htmlunit.html.FrameWindow; import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController; import com.gargoylesoftware.htmlunit.CollectingAlertHandler; import com.gargoylesoftware.htmlunit.AlertHandler; import com.gargoylesoftware.htmlunit.Page; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebWindow; import com.gargoylesoftware.htmlunit.WebWindowEvent; import com.gargoylesoftware.htmlunit.WebWindowListener; import com.gargoylesoftware.htmlunit.html.HTMLParser; import com.gargoylesoftware.htmlunit.DialogWindow; import com.gargoylesoftware.htmlunit.ImmediateRefreshHandler; import com.gargoylesoftware.htmlunit.html.HtmlTextInput; import com.gargoylesoftware.htmlunit.html.HtmlInput; import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; import com.gargoylesoftware.htmlunit.html.HtmlPasswordInput; import org.openqa.selenium.htmlunit.HtmlUnitDriver; import com.gargoylesoftware.htmlunit.html.HtmlElement; import com.gargoylesoftware.htmlunit.ScriptResult; import com.gargoylesoftware.htmlunit.xml.XmlPage; import java.util.*; import java.net.*; import java.io.*; class Connect { final static LinkedList<WebWindow> windows = new LinkedList<WebWindow>(); public static void main(String[] args)throws Exception { java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(java.util.logging.Level.OFF); java.util.logging.Logger.getLogger("org.apache.http").setLevel(java.util.logging.Level.OFF); System.setProperty("jsse.enableSNIExtension", "false"); System.setProperty("com.sun.net.ssl.enableECC", "false"); final WebClient webClient = new WebClient(new BrowserVersion("IE","5.0 (compatible: MSIE 9.0; Windows NT 6.1; Trident/5.0)","Mozilla/5.0 (compatible: MSIE 9.0; Windows NT 6.1; Trident/5.0)",9)); webClient.addWebWindowListener(new WebWindowListener() { public void webWindowClosed(WebWindowEvent event) { System.out.println("a window is CLOSED: " + event.getOldPage()); } public void webWindowContentChanged(WebWindowEvent event) { System.out.println("Content has been changed :"+event.getWebWindow()); } public void webWindowOpened(WebWindowEvent event) { System.out.println("a NEW window opened: " + event.getNewPage()); windows.add(event.getWebWindow()); } }); webClient.setAlertHandler(new AlertHandler() { public void handleAlert(Page page, String message) { System.out.println("WebClient.handleAlert:" + "\n page : " + page + "\n message: " + message); } }); webClient.getOptions().setJavaScriptEnabled(true); webClient.getCookieManager().setCookiesEnabled(true); webClient.getOptions().setCssEnabled(true); webClient.getOptions().setUseInsecureSSL(true); webClient.getOptions().setThrowExceptionOnFailingStatusCode(false); webClient.setAjaxController(new NicelyResynchronizingAjaxController()); webClient.getOptions().setThrowExceptionOnScriptError(false); webClient.getOptions().setActiveXNative(true); webClient.getOptions().setAppletEnabled(true); webClient.getOptions().setPopupBlockerEnabled(false); webClient.getOptions().setRedirectEnabled(true); //System.out.println("version="+webClient.getBrowserVersion()); String url="<application URL>"; final HtmlPage page1 = webClient.getPage(url); final HtmlForm form = page1.getFirstByXPath("<form name>"); final HtmlTextInput userName = form.getInputByName("username"); final HtmlPasswordInput password = form.getInputByName("password"); userName.setValueAttribute("admin"); password.setValueAttribute("Passw0rd"); HtmlButton submitbutton=null; List<HtmlButton> buttons = form.getButtonsByName(""); for(int i=0;i<buttons.size();i++){ HtmlButton button = buttons.get(i); if(button.getAttribute("id").equals("SubmitButton")){ submitbutton = button; break; } } try { webClient.waitForBackgroundJavaScriptStartingBefore(10000); final HtmlPage page2 = submitbutton.click(); //after login to redirect to another page i am calling java script function String javaScriptCode = "cuesInvokeDrawerURL('dPolicyElements','java script function');"; ScriptResult result = page2.executeJavaScript(javaScriptCode); webClient.waitForBackgroundJavaScript(50000); result.getJavaScriptResult(); //Required button lies on frame final HtmlPage page2_1 = (HtmlPage)webClient.getCurrentWindow().getEnclosedPage(); final List<FrameWindow> window = page2_1.getFrames(); for(int i=0;i<window.size();i++) { final HtmlPage pageTwo = (HtmlPage) window.get(i).getEnclosedPage(); HtmlButtonInput narsCreate=(HtmlButtonInput)pageTwo.getElementById("Create"); final HtmlPage page2_2 = narsCreate.click(); HtmlForm form1 = page2_2.getForms().get(0); final HtmlTextInput name = form1.getInputByName("name"); final HtmlTextInput description = form1.getInputByName("description"); //clicking button on the create1 button which will invoke a dialog window HtmlButtonInput submit_device=(HtmlButtonInput)page2_2.getElementById("Create1"); final HtmlPage page2_3 = submit_device.click(); webClient.waitForBackgroundJavaScript(7000); System.out.println(page2_3.getWebResponse().getContentAsString()); break; } } catch(Exception e) { System.out.println(e); } /* */ //webClient.closeAllWindows(); } } </code> -- View this message in context: http://htmlunit.10904.n7.nabble.com/Dialog-Box-tp35073p35095.html Sent from the HtmlUnit - General mailing list archive at Nabble.com. |