zoukankan      html  css  js  c++  java
  • Seleniumwebdriver系列教程(八)————如何操作select下拉框

    在selenium-webdriver中定位select list的方法比较简单,用id和name等属性可以很方便的将select给找出来,但是怎么去选择下拉框中的某一项呢?

    思路是这样的,首先定位到select list元素,然后找出该select list下所有的option,点击该option element既可,以下面的html代码为例

    <html>
        <head>
            <title>Select</title>
        </head>
        <body>
            <span>select demo</span>
            <select id = "s" name = "ns">
                <option value = "0">Op1</option>
                <option value = "1">Op2</option>
                <option value = "2">Op3</option>
                <option value = "3">Op4</option>
            </select>
        </body>
    </html>
     
    通过下面的代码可以选择到下拉框中的第2个option,也就是text为Op2的选项
     

    require 'selenium-webdriver'
      
    dr = Selenium::WebDriver.for :firefox
     
    select_file = 'file:///'.concat File.expand_path(File.join(File.dirname(__FILE__), 'select.html'))
     
    dr.navigate.to select_file
     
    dr.find_element(:id => 's').find_elements(:tag_name => 'option')[1].click
     
  • 相关阅读:
    [LeetCode 题解]: Triangle
    [LeetCode 题解]: pow(x,n)
    [LeetCode 题解]: plusOne
    [LeetCode 题解]: ZigZag Conversion
    error: field 'b' has imcomplete type
    两个分数的最小公倍数
    DDR工作原理
    流水线技术原理和Verilog HDL实现
    FPGA主要应用
    提高器件工作的速度
  • 原文地址:https://www.cnblogs.com/timsheng/p/2556325.html
Copyright © 2011-2022 走看看