如何使用量角器访问 POP UP window 中的文本框

How to access a textbox in a POP UP window using protractor

请有人帮助我使用量角器

访问 POP UP window 中的文本框
<div class="ngdialog-content">
<div class="ngdialog-message ngdialogCustomStyle">
<h3 class="dailog-title">Create New </h3>
<div class="div_emailTo">
<input class="input_textbox" type="text" placeholder="To">
<a class="cc-link" ng-click="show_cc=true" ng-show="!show_cc" href="#">cc</a>
</div>
<div class="ng-hide" ng-show="show_cc">
<div>
<div>
<div id="attachBtn" class="attachDocBtnContainer" ng-click="uploadBtnClick()">
<input id="browse_file" class="attachDocBrowser" type="file">
<div class="emailDialogBtns">
</div>
<div class="ngdialog-close"></div>
</div>
</div>

试试这个:

describe('Protractor Demo', function() {
it('should greet the named user', function() {    
    var emailTo = element(by.css('.div_emailTo'));
    var txtbox = emailTo.element(by.css('.input_textbox'));
    txtbox.sendKeys('***************');
  });
 });

如果它真的是一个真正的弹出窗口window那么这个有用的功能就可以派上用场了。

/**
 *[selectWindow Focus the browser to the index window.
 * @param  {[Object]} index [Is the index of the window. E.g., 0=browser, 1=FBpopup]
 * @return {[!webdriver.promise.Promise.<void>]}
 */
global.selectWindow = function(index) {
  // wait for handles[index] to exist
  browser.wait(function() {
    return browser.getAllWindowHandles().then(function(handles) {
      /**
       * Assume that handles.length >= 1 and index >=0.
       * So when calling selectWindow(index) return
       * true if handles contains that window.
       */
      if (handles.length > index) {
        return true;
      }
    });
  }, 30000);
  // here i know that the requested window exists

  // switch to the window
  return browser.getAllWindowHandles().then(function(handles) {
    return browser.switchTo().window(handles[index]);
  });
};

正如评论中所解释的那样,1 将是弹出窗口 window,而 0 将返回到浏览器,因此您可能会遇到这样的情况:

// select the pop window
selectWindow(1);
// Do stuff with the text input 
element(by.css(".input_textbox").sendKeys("something");
// Interact back with the browser and no longer with the popup
selectWindow(0);