循环访问下拉列表的选项



我在Ruby中使用Selenium(我目前正在学习的一种语言(,我有一个下拉菜单,我想迭代,选择每个选项,做一些事情,然后转到下一个选项。

我看了几个有些相似的答案。只有一个堆栈溢出问题必须与我的想法相似,但它在 Python 中,我只是不知道 Ruby 的语法。

我已经通读了 Ruby 的文档,并没有找到任何类似于 Python 方式的东西。

基本上我想做的是:

   select first option
        click a button
        navigate to a different page
        download a csv
        return back to the previous page
   select second option
        do the same thing
etc...until all the options are done

这可能吗?我可以弄清楚返回上一页并单击 csv 选项,但我希望在语法部分获得一些帮助。

谢谢

selenium-webdriver的 ruby 绑定有一个用于操作选择列表的 Select 类。

下面是一个人为的示例,该示例查找select_list元素,将该元素传递给 Select 对象,并打印列表中每个选项的文本。 扬子晚报...

require "selenium-webdriver"
driver = Selenium::WebDriver.for :firefox
driver.navigate.to "https://www.seleniumeasy.com/test/basic-select-dropdown-demo.html"
element = driver.find_element(id: 'select-demo')
select_list = Selenium::WebDriver::Support::Select.new(element)
select_list.options.each { |option| puts option.text}
#=> Please select
#=> Sunday
#=> Monday
#=> Tues
...

相关内容

最新更新