I am trying to navigate this webpage using Selenium in VBA: https://www.familysearch.org/search/collection/1401638/. I am using Chrome as the browser and inspect to see the elements in the page. I am not familiar with javascript, but am expert in VBA. I am able to navigate the elements that appear to be static on the page, such clicking the sign in button in the upper right. But I haven't figured out how to interact with the form in the center that has the tag Search Collection.
Here is the code I have so far:
Sub WebScraper()
Dim FSBrowser As New WebDriver
Dim FSWebElements As WebElements
FSBrowser.Start "chrome", "https://www.familysearch.org/search"
FSBrowser.Get "/collection/1401638/" ' United States Census, 1850
FSBrowser.FindElementById("signInLink").Click
'FSBrowser.FindElementById("userName").SendKeys ("xxxx")
'FSBrowser.FindElementById("password").SendKeys ("xxxx")
'FSBrowser.FindElementById("login").Click
FSBrowser.Quit
End Sub
I would like to enter "Virginia" in the Birth Place text box and click Search.
The complete HTML code as rendered in Inspect is really long, since there are quite a lot of form elements. Here is the form information from the javascript and the two elements:
<fs-search-form mobile-breakpoint="500">
<form id="form" method="get" class="search-form " action="/search/record/results">
<input type="text" class="fs-field-group__input" name="birthLikePlace" id="birthLikePlace">
<button type="submit" class="fs-button fs-button--recommended">Search</button>
This seems like a simple task, but I am clearly missing something. Could someone show me what that is? It looks like finding the element by name or Id of birthLikePlace would work, but it doesn't.
Edit: It seems that shadow-root has a big part to play in this issue. It is marked as open, but I suspect there is more to it that I am not seeing. Here is the complete section for the birthLikePlace:
<sf-search-field-group field-list="["birthLikePlace", "birthLikeDate"]" trigger-id="birth">
#shadow-root (open)
<style> ... </style>
<div class="field-section" visible="">
<h2 class="section-header fs-h5">KEY: null (en)</h2>
<dom-if style="display: none;"><template is="dom-if"></template></dom-if>
<dom-if style="display: none;"><template is="dom-if"></template></dom-if>
<div class="trigger-group shown active flexible-container" for="birth">
<legend role="button" class="closer " for="birth" aria-label="Hide search fields for birth"> </legend>
<slot></slot> </div> </div>
<sf-search-field field-id="birthLikePlace" field-type="place">
#shadow-root (open)
<style> ... </style>
<span class="field" visible="" field-id="birthLikePlace">
<dom-if style="display: none;"><template is="dom-if"></template></dom-if>
<span class="event-place flex-item">
<label for="birthLikePlace_place">Birthplace</label>
<span class="fs-field-group">
<input type="text" class="fs-field-group__input" name="birthLikePlace" id="birthLikePlace">
<span class="fs-field-group__attachment fs-tooltip">
<span class="fs-tooltip__trigger">
<input type="checkbox" name="birthLikePlace.exact" id="birthLikePlaceexact">
<label aria-label="Match birthplace exactly" for="birthLikePlaceexact"></label> </span>
<span class="fs-tooltip__body" role="tooltip">::before Match birthplace exactly ::after</span> </span> </span> </span>
<dom-if style="display: none;"><template is="dom-if"></template></dom-if>
<dom-if style="display: none;"><template is="dom-if"></template></dom-if>
<dom-if style="display: none;"><template is="dom-if"></template></dom-if>
<dom-if style="display: none;"><template is="dom-if"></template></dom-if>
<dom-if style="display: none;"><template is="dom-if"></template></dom-if>
<dom-if style="display: none;"><template is="dom-if"></template></dom-if>
</span>
</sf-search-field>
<sf-search-field field-id="birthLikeDate" field-type="year"> ... </sf-search-field>
</sf-search-field-group>
Set obirthPlace = FSBrowser.FindElementById("birthLikePlace", timeout:=10000): obirthPlace.SendKeys "virginia"