0

when i click on the Link , a Popup opens up. However couldn't able to work on the fields of popup as protractor can't locate the elements and then it gets timedout.

Following is the code browser.ignoreSynchronization = true;

    performancePage.go();
    logger.info('Info', 'Navigating to performance Page');
    helper.isElementVisible(performancePage.performanceTab);
    performancePage.performanceTab.click();
    element(by.id("ButtonAddProduct")).click();
    browser.driver.sleep(4000)
   var  handlePromise = browser.getAllWindowHandles();
    var handles = handlePromise.then(function (handles) {
        console.log(handles)
        popUpHandle = handles[1];
        var handle = browser.switchTo().window(popUpHandle);
        handle = browser.getWindowHandle();
        expect(handle).toEqual(popUpHandle);
        browser.driver.executeScript('window.focus();');
    });
    //helper.isElementVisible(performancePage.addProduct);
    //performancePage.addProduct.click();
    helper.isElementVisible(element(by.id("form1")));[![enter image description here][1]][1]

Also in console.log, its only showing 1 window handle and not of the Popup handle

here is the HTML:

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1">
<body>
<form id="form1" onsubmit="javascript:return WebForm_OnSubmit();" action="AddProduct.aspx" method="post">
<div class="aspNetHidden">
<script type="text/javascript"> //<![CDATA[ var theForm = document.forms['form1']; if (!theForm) {     theForm = document.form1; } function __doPostBack(eventTarget, eventArgument) {     if (!theForm.onsubmit || (theForm.onsubmit() != false)) {         theForm.__EVENTTARGET.value = eventTarget;         theForm.__EVENTARGUMENT.value = eventArgument;         theForm.submit();     } } //]]> </script>
<script type="text/javascript" src="/WebResource.axd?d=NLOzwancrFW_OxVrAGBXy-kmkOGHUYmO808scG3GJ5f98I_P9beUOmU4HNGkqJQWHiSPU9aY7onPaiTvMCtL3eBXmC_rcSTJAFJAPa_OIJw1&t=635586505120000000"/>
<script type="text/javascript" src="/ScriptResource.axd?d=K0uQ-qcyckZQ0YCESuG4YfaXFE8emO5C9Ce1KC27_VB1FRGUsYkGZcC6OJnVnIEp6qunwr4jFBAKcuX_FFlQhtiSBdTz0RYmzsqtrKC3ePqj2CqtZGDAEZ4f0TCoYf0CGDgUxlJb7An1eoe5Vvcd-YsPSDf93ysj0hatMJcw5Bk1&t=5303ace5"/>
<script type="text/javascript" src="/ScriptResource.axd?d=ICFVFfrCSHOWqdP0dm99rLOsC2_-ZnYiCw1CqjXgfBZ92x5ruBu78fP6ZyV7fADUc626lvSvIubJzd5ej_JSkHNQHZSSai511-4rfVoNIRmTJczCHqrBjZa3yIX-22uMxb3rGnoSAGlTcOHE53z7TSmGu1MNobwW3y3pLnoN-H72LyOhX5OECQ17aAmZHECd0&t=7b689585"/>
<script type="text/javascript"> //<![CDATA[ if (typeof(Sys) === 'undefined') throw new Error('ASP.NET Ajax client-side framework failed to load.'); //]]> </script>
<script type="text/javascript" src="/ScriptResource.axd?d=OL2ISgjqQODB5nkx4b5_GOgoAHxOq6FEk9tXBRu0WSmyCZCd3ccx73Jhlea-pmk11_GS4uVKb8o448Z76ihbV5xUGrVOtwriFbjM0joyKwz96l4gVfykwP91DaSn6g66OedAzY_pkY4s5--Zg_vgtAu4W2Kz6hrDw12cq5mZa1pji5zdqGZ-ZKisFszMRWz10&t=7b689585"/>
<script type="text/javascript"> //<![CDATA[ function WebForm_OnSubmit() { if (typeof(ValidatorOnSubmit) == "function" && ValidatorOnSubmit() == false) return false; return true; } //]]> </script>
<div class="aspNetHidden">
<div style="margin: 4px">
<script type="text/javascript"> //<![CDATA[ Sys.WebForms.PageRequestManager._initialize('Scriptmanager1', 'form1', [], [], [], 90, ''); //]]> </script>
<table>
<tbody>
<tr>
<td>
<td>
<input id="TextBoxProductName" type="text" name="TextBoxProductName"/>
<span id="RequiredFieldValidator1" style="visibility:hidden;">
<br/>
Please enter a product name.
</span>
</td>
</tr>
<tr>
<td>
<b>
Product Short Name
<img id="Img4" src="../Images/Asterisk.gif"/>
</b>
</td>
<td>
<input id="TextBoxShortName" type="text" name="TextBoxShortName"/>
<span id="RequiredFieldValidator2" style="visibility:hidden;">
<br/>
Please enter a product short name.
</span>
</td>
</tr>
anuvrat singh
  • 411
  • 1
  • 7
  • 20
  • It's hard to tell what's going on without seeing the html... – Brine Feb 06 '16 at 18:12
  • Sorry anuvrat, I can't be sure what the problem is with the code provided. `getAllWindowHandles` is saying there's only one window? Is this a popup window, alert, or a modal? – Brine Feb 10 '16 at 13:16
  • Hi Brine, yes, its a window popup .The popup is having 2 HTML itself. One HTML is the window and other HTML is a form inside the window. you can contact me on Skype :anuvrat.singh1 or anyother mode so we can discuss in details (if possible) – anuvrat singh Feb 10 '16 at 14:21

1 Answers1

0

Anuvrat, there's a lot of cruft in your code. You'll get better/more answers if you break it down to be more readable/understandable.

That said, something like this should work...

performancePage.go();
performancePage.performanceTab.click();
element(by.id("ButtonAddProduct")).click();
browser.sleep(4000); // assuming we're waiting for popup?

// try just switching to the window via it's index...
browser.switchTo().window(1);

// popup code goes here...

// switch back to main window
browser.switchTo().window(0);
Brine
  • 3,733
  • 1
  • 21
  • 38
  • I have tried it before also and it didnt worked. i even tried driver.switchto().ActiveElement() but that also doesn't worked :( – anuvrat singh Feb 11 '16 at 09:14
  • Switching to a window via the index doesn't work with the current version of protractor. See https://stackoverflow.com/a/42595269/360782 for the current approach. – Paul Lynch Aug 10 '18 at 19:33