2

I am working to automate an application which works in IE only.

Steps are : 1. Go to particular page and click on Search button. 2. Search button opens up a new Modal Pop up 3. I chose a company name in popup and It closes the popup and populate the details of the selected company in parent window.

But since, there is no way to handle Modal pop in IE with selenium, I have explicitly used:

                   ((JavascriptExecutor) driver).executeScript("window.showModalDialog =window.open;");

Issue is: When modaldialog is opening up as window through my code and I choose company,it closes but It doesn't populate details in Parent window.

This is the HTML for the button which opens popup:

        <input id="ctl00_cphMain_ucCustomer_ctlModalBuyerCompany_btnModal"  class="FormButton" type="submit" onclick="javascript:ModalCallerCtl_Popup('ctl00_cphMain_ucCustomer_ctlModalBuyerCompany','Please+specify+a+Buyer+Company',1200, 700,'btnModal'); return true;" value="..." name="ctl00$cphMain$ucCustomer$ctlModalBuyerCompany$btnModal">

This is the HTML for element I am click to choose the company name and close the popup:

         <tr id="SearchxresultsGrid_r_8" level="8" style="height:21px;">
            <td id="SearchxresultsGrid_rc_8_0" class="ig_6cb4695_r1 GridRow UltraWebGridRow ig_6cb4695_rc11 FormGridCellText" onmousedown="return igtbl_cancelEvent(event);">
            <nobr>
            <input class="ig_6cb4695_rcb1112 SelectionSearch btnOpenSite" type="button" tabindex="-1" onclick="igtbl_colButtonClick(event,'SearchxresultsGrid',null, igtbl_srcElement(event));" value="" style="">
            </nobr>

I am iterating over the windows and doing action:

                        while(i.hasNext())
                    {
                        String child = i.next();
                        if(child!=parent_wnd){
                            System.out.println(" Child window -----  " + child);

                            driver.switchTo().window(child);

                            driver.switchTo().frame("ifrContent");
                            WebElement SearchBtn = driver.findElement(By.xpath(".//*[@id='Search_GoButton']"));

                            SearchBtn.click();

                            Thread.sleep(90000);
                            util.jsJqWait(driver);
                            wait.until(ExpectedConditions.elementToBeClickable(By.xpath(".//*[@id='Search_FieldSelect0_txtValue1']")));


                            /*WebElement txtbox = driver.findElement(By.xpath(".//*[@id='Search_FieldSelect0_txtValue1']"));

                            txtbox.sendKeys("PHD");
                            */


                            //WebElement btn = driver.findElement(By.id("SearchxresultsGrid_rc_8_0"));


                            WebElement company_PHD= driver.findElement(By.xpath("//td[@id='SearchxresultsGrid_rc_8_0']/nobr/input"));

                            //executor.executeScript("var a = document.evaluate(\"//td[@id='SearchxresultsGrid_rc_8_0']/nobr/input\", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; return a.onclick=\"igtbl_colButtonClick(event,'SearchxresultsGrid',null, igtbl_srcElement(event))\";");

                            //executor.executeScript("return document.evaluate(\"//td[@id='SearchxresultsGrid_rc_8_0']/nobr/input\", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.click();");

                            executor.executeScript("var a = document.evaluate(\"//td[@id='SearchxresultsGrid_rc_8_0']/nobr/input\", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; return a.onclick='WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(\"Search$GoButton\", \"\", true, \"\", \"\", false, false)';");


                            //executor.executeScript("window.addEventListener(\".\"), function('igtbl_colButtonClick(event,'SearchxresultsGrid',null, igtbl_srcElement(event))');");
                            util.safeJavaScriptClick(company_PHD, driver);

                            //executor.executeScript("window.opener.igtbl_colButtonClick(event,'SearchxresultsGrid',null, igtbl_srcElement(event));");

                            //executor.executeScript("jQuery('#company_PHD').click()");

                            //executor.executeScript(" return window.opener.postmessage(\"return document.evaluate(\"//td[@id='SearchxresultsGrid_rc_8_0']/nobr/input\", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.click();\")");

                        }

                        driver.switchTo().window(parent_wnd);

                    }

Ignore the code. It needs to be refactored as I am just checking feasibility of automating an application.

Any suggestions or advises will be helpful. What I am looking is some explicit way/code to using JS in selenium to send the data from child window to parent window on click. I am not sure about the usage of window.opener and postmessage and need help with JS part for that.

nit22
  • 29
  • 2

0 Answers0