【问题标题】:How to select the value of a drop down如何选择下拉列表的值
【发布时间】:2018-04-28 11:48:56
【问题描述】:

我正在尝试使用casperJS 在下拉列表中进行选择和选项。我的html

<select data-role="none" id="selectStatus">

<option value="SINGLE">Single</option>
<option value="MARRIED_FILING_JOINTLY">Married Filing Jointly</option>
<option value="MARRIED_FILING_SINGLY">Married Filing Separately</option>
<option value="HEAD_OF_HOUSEHOLD">Head of Household</option></select>

而我的 JS 是

var status = 2; // Single , Married Filing Jointly , Married Filing Separately , Head of Household
//trying different ideas here... 
if(status == 1){
            status = 'SINGLE';
        }else if(status == 2){
            status = 'HEAD_OF_HOUSEHOLD';   
        }else if(taxFilingStatus == 3){
            status = 'MARRIED_FILING_JOINTLY';  
        }else if(taxFilingStatus == 4){
            status = 'MARRIED_FILING_SINGLY';   
        }

this.evaluate(function () {
        $('#selectStatus').val(status).change();
    });
    this.echo(status);
    this.capture(CapturePath('StatusSelected.png'));

当作为变量传递时,我没有得到选择的状态,但是当我像这样传递变量时

$('#selectStatus').val('SINGLE').change();

任何提示这里有什么问题?传递字符串有什么限制吗?

【问题讨论】:

    标签: select phantomjs casperjs


    【解决方案1】:

    你没有在page.evaluate 中传递status 变量,所以它在浏览器上下文中是未定义的,因此它不起作用。

    通过它的正确方法:

    this.evaluate(function (status) {
        $('#selectStatus').val(status).change();
    }, status);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多