"select"}-6ren"> "select"}-我想使用带有 watir-webdriver 的 Ruby 从下拉框中选择值。这是命令 browser.select_list(:id, "ctl00_SampleContent_ComboBox1_-6ren">
gpt4 book ai didi

ruby - 无法定位元素,使用 { :id= >"", :tag_name= >"select"}

转载 作者:数据小太阳 更新时间:2023-10-29 08:39:18 26 4
gpt4 key购买 nike

我想使用带有 watir-webdriver 的 Ruby 从下拉框中选择值。这是命令

browser.select_list(:id, "ctl00_SampleContent_ComboBox1_ComboBox1_OptionList").select("Whiskey")

我得到了一个错误无法定位元素,使用 {:id=>"ctl00_SampleContent_ComboBox1_ComboBox1_OptionList", :tag_name=>"select"}

有什么问题吗?这是完整的代码:

# 1.Open http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/Default.aspx
#browser = Watir::Browser.new
#browser = Watir::Browser.new :ie
profile = Selenium::WebDriver::Firefox::Profile.from_name 'WatirWebDriver'
#profile.add_extension 'autoauth-2.1-fx+fn.xpi'
browser = Watir::Browser.new :firefox, :profile => profile
browser.goto 'http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/Default.aspx'

#2.Click ComboBox link on the left pane of the page
browser.a(:id, 'ctl00_SamplesLinks_ctl15_SamplesLink').click

#3.Verify that http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/ComboBox/ComboBox.aspx URL opened
if browser.url.eql? "http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/ComboBox/ComboBox.aspx"
puts "Error loading page \"http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/ComboBox/ComboBox.aspx URL opened\""
return false
end

#4.Select “Whiskey” in the combo-box
#browser.select_list(:id, 'ctl00_SampleContent_ComboBox1_ComboBox1_OptionList').select_value('Whiskey')
puts "!!!"
browser.select_list(:id, "ctl00_SampleContent_ComboBox1_ComboBox1_OptionList").when_present.select("Whiskey")

最佳答案

这完成了工作:

require "watir-webdriver"
browser = Watir::Browser.new
browser.goto "http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/ComboBox/ComboBox.aspx"
browser.button(id: "ctl00_SampleContent_ComboBox1_ComboBox1_Button").click
browser.ul(:id, "ctl00_SampleContent_ComboBox1_ComboBox1_OptionList").li(text: "Whiskey").click

关于ruby - 无法定位元素,使用 { :id= >"", :tag_name= >"select"},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14503245/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com