如何选择下拉选项下protractorjs端到端测试

如何选择下拉选项下protractorjs端到端测试

本文介绍了如何选择下拉选项下protractorjs端到端测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想选择从下拉用量角器角端到端测试的选项。

下面是选择选项的code片断:

 <!选择一个id =locregion级=create_select NG-质朴的NG-无效NG-无效,要求要求=NG-禁用=organization.id = =未定义NG选项=o.id作为o.name邻组织中NG模型=organization.parent_id>
    <?期权价值=选择=选择>< /选项>
    <期权价值=0> Ranjans手机测试与LT; /选项>
    <期权价值=1> BeaverBox测试与LT; /选项>
    <期权价值=2> BadgerBox< /选项>
    <期权价值=3> CritterCase< /选项>
    <期权价值=4> BoxLox< /选项>
    <期权价值=5> BooBoBum< /选项>
< /选择>

我曾尝试:

  ptor.findElement(protractor.By.css('选择选项:1'))点击();

这给了我以下错误:

指定了无效或非法字符串
构建信息:版本:2.35.0,修订版:'c916b9d,时间:2013年8月12日15时42分01秒
系统信息:os.name:Mac OS X的,os.arch:x86_64的',os.version:'10 .9,java.version:1.6.0_65
驱动方式:driver.version:未知

我也尝试:

<$p$p><$c$c>ptor.findElement(protractor.By.xpath('/html/body/div[2]/div/div[4]/div/div/div/div[3]/ng-include/div/div[2]/div/div/organization-form/form/div[2]/select/option[3]')).click();

这给了我以下错误:

Can anyone please help me with this problem or throw some light on what i might be doing wrong here.

解决方案

I had a similar problem, and eventually wrote a helper function that selects dropdown values.

I eventually decided that I was fine selecting by option number, and therefore wrote a method that takes an element and the optionNumber, and selects that optionNumber. If the optionNumber is null it selects nothing (leaving the dropdown unselected).

var selectDropdownbyNum = function ( element, optionNum ) {
  if (optionNum){
    var options = element.findElements(by.tagName('option'))
      .then(function(options){
        options[optionNum].click();
      });
  }
};

I wrote a blog post if you want more detail, it also covers verifying the text of the selected option in a dropdown: http://technpol.wordpress.com/2013/12/01/protractor-and-dropdowns-validation/

这篇关于如何选择下拉选项下protractorjs端到端测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 04:02