Selenium2Library - Safari无法从下拉列表中选择

时间:2017-06-02 00:10:55

标签: safari robotframework selenium2library

我在页面上有两个下拉菜单。我需要验证下拉列表1中的项目是否为"选择"添加到下拉列表2中的项目时添加到它。下拉列表1中有超过3个选项,但我想在帖子中节省空间。第一个步骤获取列表中所有项目的值,并随机选择一个。

第二部分使用在前几个步骤中随机选择的值来定位选项,并查看选中的类是否为true。

这是HTML:

<ol>
     <li class="select input required" id="message_recipient_input">
          <select id="message_recipient_id">
               <option value></option>
               <option value="1">Smith, Bob</option>
               <option value="2">Smith, Steve</option>
               <option value="3">Smith, Joe</option> 
          </select>
     </li>
</ol>

<ol>
     <li class="select input required" id="message_template_input">
          <select id="message_template_id">
               <option value></option>
               <option value="9">Message Template</option>
               <option value="10">Survey Template</option>
               <option value="11">Coupon Template</option> 
          </select>
     </li>
</ol> 

以下是RF中的步骤:

${RecipientCount}=      Get Matching Xpath Count        xpath=//*[@id="message_recipient_id"]/option
Log                     ${RecipientCount}
@{ValueList}=           Create List
: FOR       ${INDEX}    IN RANGE       1            ${RecipientCount}
\       ${recipient_value}=        Get Element Attribute    xpath=//*[@id="message_recipient_id"]/option[contains(text(), '@')] [${INDEX}]@value
\       Log                        ${recipient_value}
\       Append To List             ${ValueList}             ${recipient_value}
Log                     ${ValueList}
${recipient}=           Evaluate            random.choice(${ValueList})       random
Log                     ${recipient}
Sleep                   2s
Select From List        id=message_recipient_id       ${recipient}
Sleep                   2s

${message_template_dropdown}=   Select From List By Value       id=message_template_id          9
Sleep                           2s
${selected_recipient}=          Get Element Attribute           xpath=//option[@value=${recipient}] @selected
Log                             ${selected_recipient}
Should Contain                  ${selected_recipient}           true

这适用于Mac OS X上的Chrome和Firefox,但Safari并未选择列表中的任何项目。这些步骤通过就好像它正在选择它们但是在&#34;应该包含&#34; step因为$ {selected_recipient}对所选类没有None。

0 个答案:

没有答案