尝试在root url
上访问此按钮:
这里是html
进行此测试:
feature "New comment button" do
scenario "User can add new comment on root page", :js => true do
visit root_path
id = 152
click_button("#button_#{id}")
within("#comment_row_#{id}") do
fill_in('content', :with => 'this is a comment')
click_button('create comment')
page.must_have_flash_message('Successfully created')
end
end
并提出这个问题:
Capybara::ElementNotFound: Unable to find button "#button_152"
如何使用id
获取此元素?
我正在使用selenium-web-driver
修改
我做了什么
# page.driver.browser.switch_to.frame 'top-frame' # Selenium::WebDriver::Error::NoSuchFrameError: Unable to locate frame: top-frame
# page.find('#button_152').click # not working
# click_button("#button_152") # not working
# first(:xpath, '//button[@id="button_152"]').click
2.这是框架的概述:
google chrome addons
答案 0 :(得分:0)
您可以在此处阅读有关切换窗口和框架的信息:http://docs.seleniumhq.org/docs/03_webdriver.jsp#moving-between-windows-and-frames
Ruby特定绑定:https://code.google.com/p/selenium/wiki/RubyBindings
处理iframe的Capybara:handling iframe with capybara ruby
至于你的问题,这里有一个你可以编辑的例子:
within_frame 'evernoteFilingTools' do
click_button("#button_#{id}")
#button_#{id} # not working
#page.find("#button_#{id}",:visible => true).click # does not work as well
within("#comment_row_#{id}") do
fill_in('content', :with => 'this is a comment')
click_button('create comment')
page.must_have_flash_message('Successfully created')
end
end
您应该将evernoteFilingTools替换为包含您要操作的内容的iframe ID
答案 1 :(得分:0)
有时候,它可能会因无效标记而被抛弃。此HTML在表格中有div
(<div class="icons">
),无效。尝试通过http://validator.w3.org/等验证程序运行标记,并修复它报告的任何错误。这也可能会解决你的水豚问题。