-2

http://demos.telerik.com/aspnet-ajax/combobox/examples/functionality/checkboxes/defaultcs.aspx

我能够获得选项总数,但无法获得文本。

4

2 回答 2

1

尝试以下。它在我的最后工作:

require 'selenium-webdriver'
driver = Selenium::WebDriver.for :firefox

driver.get "http://demos.telerik.com/aspnet-ajax/combobox/examples/functionality/checkboxes/defaultcs.aspx"

el = driver.find_element(:id, "ctl00_ContentPlaceHolder1_RadComboBox1_Arrow")
el.click

list = driver.find_element(:xpath, "//ul[@class='rcbList']")
options = list.find_elements(:xpath, ".//li/label")
options.each do |option|
    puts option.text
end
于 2013-07-18T12:57:37.297 回答
0

无论使用或不使用Selenium::WebDriver::Wait.

这是完整的代码(我在没有使用WebDriverWait的情况下注释掉了版本,两个版本都应该可以工作):

require 'selenium-webdriver'

driver = Selenium::WebDriver.for :firefox
driver.get('http://demos.telerik.com/aspnet-ajax/combobox/examples/functionality/checkboxes/defaultcs.aspx')

wait = Selenium::WebDriver::Wait.new(:timeout => 10) # seconds

# without wait
# combo = driver.find_element(:id => 'ctl00_ContentPlaceHolder1_RadComboBox1_Input')
# combo.click

# with wait
combo = wait.until { driver.find_element(:id => "ctl00_ContentPlaceHolder1_RadComboBox1_Input") }
combo.click

# without wait
# all_labels = driver.find_elements(:css => '#ctl00_ContentPlaceHolder1_RadComboBox1_DropDown .rcbItem label')

# with wait
all_labels = wait.until { driver.find_elements(:css => '#ctl00_ContentPlaceHolder1_RadComboBox1_DropDown .rcbItem label') }
all_labels.each do |label|
  puts label.text
end
puts all_labels.count
于 2013-07-18T10:23:07.133 回答