Javascript Selenium:将弹出窗口中的数据发送到IE11中不通过JS工作的父级
我正在努力使一个只在IE中工作的应用程序自动化 步骤如下: 1.转到特定页面并单击搜索按钮。 2.搜索按钮打开一个新的模式弹出窗口 3.我在弹出窗口中选择了一个公司名称,它关闭弹出窗口并在父窗口中填充所选公司的详细信息 但是,由于无法使用selenium处理IE中的模式弹出,因此我明确使用:Javascript Selenium:将弹出窗口中的数据发送到IE11中不通过JS工作的父级,javascript,selenium,postmessage,window.opener,modalpopup,Javascript,Selenium,Postmessage,Window.opener,Modalpopup,我正在努力使一个只在IE中工作的应用程序自动化 步骤如下: 1.转到特定页面并单击搜索按钮。 2.搜索按钮打开一个新的模式弹出窗口 3.我在弹出窗口中选择了一个公司名称,它关闭弹出窗口并在父窗口中填充所选公司的详细信息 但是,由于无法使用selenium处理IE中的模式弹出,因此我明确使用: ((JavascriptExecutor) driver).executeScript("window.showModalDialog =window.open;");
((JavascriptExecutor) driver).executeScript("window.showModalDialog =window.open;");
问题是:当modaldialog通过我的代码打开为窗口时,我选择了公司,它会关闭,但不会在父窗口中填充详细信息
这是打开弹出窗口的按钮的HTML:
<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">
忽略代码。它需要重构,因为我只是在检查自动化应用程序的可行性
任何建议都会有帮助。
我正在寻找的是在selenium中使用JS在单击时将数据从子窗口发送到父窗口的一些显式方法/代码。我不确定window.opener和postmessage的用法,需要JS部分的帮助
<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>
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);
}