Watir はdata-
型属性をロケーターとして使用することをサポートしています (つまり、xpath を使用する必要はありません)。ダッシュをアンダースコアに置き換え、先頭にコロンを追加するだけです。
以下を使用して div を取得できます (属性のロケーターの形式に注意してください: data-loc-type -> :data_loc_type ):
browser.div(:class => 'location_picker_type_level', :data_loc_type => '1')
このタイプの div が 1 つしかないことが予想される場合は、次のようにしてテーブルがあることを確認できます。
div = browser.div(:class => 'location_picker_type_level', :data_loc_type => '1')
puts div.table.exists?
#=> true
一致する複数の div があり、それらの少なくとも 1 つにテーブルがあることを確認したい場合は、コレクションのany?
メソッドを使用します。divs
#Get a collection of all div tags matching the criteria
divs = browser.divs(:class => 'location_picker_type_level', :data_loc_type => '1')
#Check if the table exists in any of the divs
puts divs.any?{ |d| d.table.exists? }
#=> true
#Or if you want to get the div that contains the table, use 'find'
div = divs.find{ |d| d.table.exists? }