我遇到了一个问题,我创建了一个测试,我会随机地得到这个问题,从我的理解是因为有java脚本运行定期刷新元素。我不确定如何阻止这个错误发生,这里是我的测试代码;Watir“元素不再附加到DOM”错误
编辑:诚如我已经移除变量的元素,并直接调用它们,但错误依然存在,这是我更新的代码和错误信息(包括行号)
47 When(/^I click the create room button$/) do
49 Watir::Wait.for_condition(10, 2, "Waiting for room data to load") {
50 @browser.iframe(:id, 'iconsole-plugin-session_iframe__').div(:id, 'lobby_rooms').div(:id, 'room_list').present?
51 }
53 rooms = []
55 @browser.iframe(:id, 'iconsole-plugin-session_iframe__').div(:id, 'lobby_rooms').div(:id, 'room_list').as.each do |room |
56 rooms << room.attribute_value('data-room-id')
57 end
59 puts roomvalue = rooms.size.to_i
61 @current_rooms = rooms
63 roomvalue
65 Watir::Wait.for_condition(10, 2, "Waiting for button to be present") {
66 @browser.iframe(:id, 'iconsole-plugin-session_iframe__').button(:id, 'create_room_form_button').present?
67 }
68 @browser.iframe(:id, 'iconsole-plugin-session_iframe__').button(:id, 'create_room_form_button').click
69 end
的错误我越来越是;
Element is no longer attached to the DOM - {:element=>#<Selenium::WebDriver::Element:0x68d78665e583d27c id="{80a6296c-fc63-4d63-917c-9a2bf35bb429}">} (Watir::Exception::UnknownObjectException)
./features/step_definitions/multiplayer_fe_steps.rb:56:in `block (2 levels) in <top (required)>'
./features/step_definitions/multiplayer_fe_steps.rb:55:in `/^I click the create room button$/'
features/multiplayer_fe.feature:21:in `When I click the create room button'
由于钢提供的答案,但是,即使元素被直接放入等待语句,我得到了同样的错误,是有什么事,我可以尝试解决这个问题?
编辑:我已经尝试使用lamda作为我的列表,但是当我这样做时,我会得到一个不同的错误,说'未定义的方法'为'.as.each do | room |
由于钢所提供的答案,但是,即使元素被直接放入等待声明我得到同样的错误,还有什么我可以尝试解决问题? – Ethranes
如果您使用了该代码,我可以再看一次。在代码中注意标记第63行,错误行?我还用一些更多的想法更新了我的答案,包括处理存储参考的第二个变量,以及为什么这是一个不好的模式。 – steel
感谢钢铁公司,我在主要文章中更新了我的代码和错误 – Ethranes