Search code examples
rubyseleniumwatirshadow-dom

Ruby, Watir, and how to fill out text fields inside of a Shadow DOM? (Safari)


EDIT: PARTIAL SOLUTION FOUND: I was using Safari. Running the task through Chrome made turned what was in the Shadow DOM into the Light Dom so that I can now access it!

I am attempting to automate a browser task and automate some form filling with Watir, but I am having the hardest time trying to fill out text boxes in Shadow DOMs.

Image of the text field:

https://i.sstatic.net/k1KAk.png

This is the corresponding HTML for the Postal Code text field:

<input class="textbook" id="Fm2_Ctrol19_TextBox" name="Fm2_Ctrol19_TextBox" 
onchange="SearchJs.setBackgroundColor(this, SearchJs.checkTextBox_;" 
onkeypress="return 
SearchJS.onTextBoxKeyPress(event, this);" 
onkeyup="SearchJs.setBackgroundColor(this,SearchJs.checkTextBox);" 
onpaste="return SearchJs.onTextBoxPaste(event, this);" style="width:100px;
background=color: #ffffff;"
title="The zip code in which the property is located." type="text"> =$0

Shadow Content (User Agent) # The text field is in here, I imagine.

</input>

I am not familiar enough with javascript and Shadow DOM to know if the articles I have googled are relevant.

I have tried using plain' Watir in the past, but it comes out Watir::Exception::UnknownObjectException (timed out after 30 seconds, waiting for #<Watir::TextField: located: false; {:id=>"Fm2_Ctrol19_TextBox", :tag_name=>"input"}> to be located) after a 30 second time out.

 b.text_field(id: 'Fm2_Ctrol19_TextBox').set 'POSTAL CODE HERE' # What I've tried

Does anyone have any information that could help me fill out that box?


Solution

  • PARTIAL SOLUTION FOUND: I was using Safari. Running the task through Chrome made turned what was in the Shadow DOM into the Light Dom so that I can now access the data!