how to avoid the iteration when I use shadow root

30 Views Asked by At

I have developed a program using Watir 7.2 that clicks on a specific option. However, due to the presence of a shadow root, I have to use an iteration to locate the desired element. If there is no shadow root, I can easily locate the element directly. Is there a way to avoid the iteration when dealing with shadow roots?

require 'watir'    
b = Watir::Browser.new    
b.goto 'url'       
b.element(id: "login-combo").shadow_root.element(id: 'toggleButton').click
b.element(id: 'overlay')
 .shadow_root
 .div(id: 'overlay')
 .div(id: 'content')
 .shadow_root
 .div(id: 'scroller')
 .elements(role: 'option').each do |element|
  if element.shadow_root.div.text.eql? 'training_us_02'
    element.shadow_root.div(text: 'training_us_02').click
    break
  end
end
0

There are 0 best solutions below