无法在量角器

时间:2016-02-05 11:46:44

标签: protractor

当我点击链接时,弹出窗口打开。然而,由于量角器无法定位元素然后它会超时,因此无法在弹出域中工作。

以下是代码 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]

同样在console.log中,它只显示1个窗口句柄而不是弹出句柄

这是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>

1 个答案:

答案 0 :(得分:0)

Anuvrat,你的代码中有很多瑕疵。如果您将其分解为更易读/可理解,您将获得更好/更多答案。

那就是说,这样的事情应该有用......

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);