关于 ruby??:如何处理 Watir::Exception::UnknownObjectException: | 珊瑚贝

How to handle Watir::Exception::UnknownObjectException:


我正在使用 watir 来使用 while 循环自动删除元素,但是当脚本到达末尾时,它会出错,因为 while 循环所依赖的元素不再可见。无论如何要让 Watir 继续进行测试吗?

这是我的代码示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Delete_element

  def org_roster_remove
    parameters = Tt_parameters.new
    driver = Login.new.log_in(parameters.username3, parameters.password3)
    while driver.a(:data_class, ‘home.group.edit_group_btn’).visible? == true
      driver.p(:data_class, ‘home.conv.messagePreview’).hover
      sleep(1)
      driver.div(:class, ‘delete’).click
      sleep(1)
      driver.a(:data_class, ‘home.conv.deleteFromRoster_btn’).click
      sleep(1)
    end
    driver.quit
  end
end

这是错误:

Watir::Exception::UnknownObjectException: unable to locate element, using {:data_class=>”home.group.edit_group_btn”, :tag_name=>”a”}

  • 我认为您想使用 present? 而不是 visible?。查看这个最近的 SO 问题:stackoverflow.com/questions/25877525/…


我会使用 .present?而不是 .visible?

还可以考虑使用 .wait_until_visible 而不是hibernate。请参阅 Watir-webdriver 等待。

另外,研究一个页面对象框架,例如 Cheezy 的页面对象 gem

  • 谢谢你。 Cheezy 的东西很有帮助


来源:https://www.codenong.com/26391070/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_9440.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?