如何在perl的selenium远程webdriver中看不到的dropdownlist(使用AJAX)中输入值

时间:2014-01-02 06:43:31

标签: ajax perl selenium remotewebdriver

在selenium中,我想在下拉列表中输入值。

我尝试了各种方法,没有任何方法可以帮助我:

  1. $driver->find_element("//select[\@id='expiry-date-month']/option[\@value='4']")->click();
    
  2. my $element = $driver->find_element('expiry-date-month','id');
    my @arry= $element->find_elements->('option','value');
    foreach my $option (@arry)
    { 
        if $option->get_text() =='5';
        {
            $option.click(); 
        }
    }
    
  3. 当我没有收到任何错误消息时,我想选择月份复选框值,请向我显示此解决方案

    HTML code:

    <form id="form-credit-card" method="get" enctype="application/x-www-form-urlencoded" novalidate="novalidate">
    <div class="row-fluid"/>
    <div class="row-fluid">
    <div class="row-fluid card-wrap">
    <div class="row-fluid name-wrap">
    <div class="row-fluid dob-wrap hide" style="opacity: 0;">
    <div class="row-fluid maestro-wrap hide" style="opacity: 0;">
    <div class="row-fluid">
    <div class="span3 iframe expiry-wrap">
    <label for="expiry-date">Expiration date</label>
    <select id="expiry-date-month" class="expirydatemonth selectBox" size="1" name="expirydatemonth" style="display: none;">
    <option value="">Month</option>
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    <option value="6">6</option>
    <option value="7">7</option>
    <option value="8">8</option>
    <option value="9">9</option>
    <option value="10">10</option>
    <option value="11">11</option>
    <option value="12">12</option>
    </select>
    <a class="selectBox expirydatemonth selectBox-dropdown selectBox-active" style="width: 30px; display: inline-block; -moz-user-select: none;" title="" tabindex="0">
    <span class="selectBox-label" style="width: 0px;">Month</span>
    <span class="selectBox-arrow"/>
    </a>
    <span class="slash">/</span>
    <select id="expiry-date-year" class="expirydateyear selectBox" size="1" name="expirydateyear" style="display: none;">
    <a class="selectBox expirydateyear selectBox-dropdown" style="width: 30px; display: inline-block; -moz-user-select: none;" title="" tabindex="0">
    </div>
    

1 个答案:

答案 0 :(得分:-1)

我在Java中使用下面的代码不太确定perl语法。可能会帮助你

WebElement dropDownListBox = driver.findElement(By.id("expiry-date-month"));
Select clickThis = new Select(dropDownListBox);
clickThis.selectByVisibleText("3");