2016-08-22 97 views
-1

我不知道为什么这个量角器代码适用于弹出窗口。 我量角器版本:4.0.3 Chrome版本:chromedriver_2.22.exe无法点击量角器中的弹出确定按钮

下面

的是,我得到

失败的错误消息:没有警报开放 (会话信息:铬= 52.0.2743.116) (驱动程序信息:chromedriver = 2.22.397933(1cab651507b88dec79b2b2a22d1943c01833cc1b),平台= Windows NT的6.1.7601 SP1 x86_64的) 堆栈: NoSuchAlertError:毫无戒备开 (会话信息:铬= 52.0.2743.116) (驾驶员信息:chromedriver = 2.22.397933(1cab651507b88dec79b2b2a22d1943c01833cc1b),platform = Windows NT 6.1.7601 SP1 x86_64)

0 。

HTML脚本用于弹出

<div class="modal-content" modal-transclude=""><div class="popupAlert popupAlert-full marginNone ng-scope"> 
    <div class="popup-header"> 
     <h2 class="modal-title ng-binding" id="myModalLabel">You are leaving this page </h2> 
    </div> 
    <div class="popup-body"> 
     <div class="row Margin0"> 
      <p class="text ng-binding">By continuing all the SLI data will be lost.</p> 
     </div> 
    </div> 
    <div class="popup-footer"> 
     <div class="row Margin0"> 
      <a data-ng-click="cancel()" class="pull-right buttonLink2">Cancel 
      <button type="button" class="pull-right swc_button" focus-element="autofocus" data-dismiss="modal" ng-click="ok()">Ok</button> 
     </a></div><a data-ng-click="cancel()" class="pull-right buttonLink2"> 
    </a></div><a data-ng-click="cancel()" class="pull-right buttonLink2"> 
</a></div></div> 

量角器代码

变种popupAlert = browser.switchTo()警报();

var alertText = popupAlert.getText(); 
    console.log(" Alert text :" +alertText); 
    popupAlert.accept(); 

// expect(popupAlert.accept).toBeDefined();

回答

0

检查您是否编写了打开警告框的代码。

这是通过使用browser.pause()。这就像量角器中的一个断点,在做一个动作来打开警告框并使用键来继续量角器测试(不要等太久,量角器会引发超时异常)。

+0

是的,我已经写了 –

+0

browser.get(“URL)。 –

+0

元素(by.linkText(linktext_locator))点击(); –

1

browser.switchTo().alert()只有当您弹出的是Javascript警告框时才能使用。在你的场景中,弹出窗口是使用HTML代码生成的,并且可以作为普通的webelement捕获。使用下面的代码来接受弹出窗口。

element(by.css(".popupAlert")).isDisplayed().then(function(isDisplayed){  
    if(isDisplayed){ 
     element(by.css(".popup-footer a")).click() //to close the alert 
     //or 
    element(by.css(".popup-footer button")).click() //to accept the alert 
    } 
}) 
+0

即使它是HTML popup仍然需要切换然后我只能点击取消链接或点击提交按钮 –

+0

HTML弹出窗口不过是一个重叠在你的网页上的div元素,这些弹出窗口被称为模态窗口。在s充足的bootstrap模态窗口可以更好地理解模态窗口的工作方式。 [Bootstrap modal windows](http://getbootstrap.com/javascript/#modals) –

1

我同意@ Sudarshan的回答你没有JavaScript警报那里,它是一个简单的HTML弹出窗口。然而,由于弹出需要显示一段时间,根据我使用ExpectedConditions的经验,它可以被有效地捕获。

var EC = protractor.ExpectedConditions; 
var popup = $('popupAlert'); 
var okButton = element(by.buttonText('Ok')); //pls use appropriate locators incase this doesn't work! 
popup.click(); 
browser.wait(EC.visibilityOf(okButton),5000); 
okButton.click();