首页 文章

在Selenium IDE中,如何在下拉菜单中按索引选择选项?

提问于
浏览
2

问题是选项标签发生变化,因此我无法通过标签抓取 . 我需要通过说选项[0] grab

任何的想法?

我正在使用Selenium IDE(Firefox),这是我要问的一块:

<tr>
    <td>select</td>
    <td>dateRangeString</td>
    <td>index=1</td>
</tr>

最后一个TD在IDE中有VALUE字段,

我已经定位了select元素,但我需要模拟用户选择第一个选项 . 我看到这样做的唯一方法是在IDE的VALUE部分使用LABEL =“string”,但字符串是动态的,因此不起作用!

6 回答

  • 0

    在selenium IDE我用过:

    命令:选择目标:以select(非选项)结尾的XPath目标 . 可以使用FireBug和FirePath获取XPath . Value :E.G . “德克萨斯”或您需要的任何 Value 模式

  • 0

    例如:

    select | Locator | index=1 |
    

    它对我有用 .

  • 11

    整蛊,但“类型”命令帮助我:

    <tr>
        <td>type</td>
        <td>id=numStuff</td>
        <td>1</td>
    </tr>
    

    相应的html看起来像这样(除了@id和@name属性)

    <select id="numStuff" name="numStuff">
                            <option selected= value="0">0</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>
    </select>
    

    我想知道它是否适用于超过1次击键的选项值 . 至少,它暂时是好的 .

  • 3

    您可以使用XPath //select/option[index] 选择它 .

    请记住,XPath是标准的基于1的索引 .

    Edit After Question was updated

    您可以使用多种不同方式从选择中选择一个选项 . 下面已经从Selenium IDE中复制了如何创建选项定位器 . 要选择第一个项目,它将是 index=0

    select(selectLocator,optionLocator)参数:* selectLocator - 标识下拉菜单的元素定位器

    • optionLocator - 选项定位器(默认为标签)

    使用选项定位器从下拉列表中选择一个选项 .

    选项定位器提供了指定HTML选项的不同方法
    选择元素(例如,用于选择特定选项,或用于断言所选选项满足规范) . 选择选项定位器有多种形式 .

    * label=labelPattern: matches options based on their labels, i.e. the visible text. (This is the default.)
              o label=regexp:^[Oo]ther
        * value=valuePattern: matches options based on their values.
              o value=other
        * id=id: matches options based on their ids.
              o id=option1
        * index=index: matches an option based on its index (offset from zero).
              o index=2
    

    如果未提供选项定位器前缀,则默认行为为
    在标签上匹配 .

  • 6

    而不是使用label =“”,尝试使用index =“1”(以选择第一个元素) . 对于这种情况,Selenium提供label =“”,id =“”,value =“”和index =“” . 有关详细信息,请参阅:

    http://release.seleniumhq.org/selenium-core/0.8.0/reference.html

  • 0

    在C#中,我通过使用:selenium.Select(“id = yourID”,“index =”i.ToString())解决了这个问题 .

相关问题