首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用量角器访问弹出窗口中的文本框

如何使用量角器访问弹出窗口中的文本框
EN

Stack Overflow用户
提问于 2015-08-04 10:08:08
回答 2查看 2.7K关注 0票数 0

请有人帮我用量角器访问弹出窗口中的文本框。

代码语言:javascript
复制
<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>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-08-04 16:25:40

尝试如下:

代码语言:javascript
复制
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('***************');
  });
 });
票数 1
EN

Stack Overflow用户

发布于 2015-08-04 21:32:39

如果它真的是一个弹出窗口,那么这个有用的函数就会派上用场。

代码语言:javascript
复制
/**
 *[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中所解释的那样,1将是弹出窗口,0将返回到浏览器,因此您可以使用这样的场景:

代码语言:javascript
复制
// 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);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31806393

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档