Make public Selector.Sel or getter Selector.Sel()
I wasn't sure whether to just raise a PR or open an issue to discuss, so have gone for the latter as there are implementation options, or maybe a very good reason for just not allowing. I'm happy to make the change myself, but don't want to go down the road of forking the repo and utilising my own feature if the principle of it is going to be rejected.
Feature Request
Add public getter Sel() to type Selector.
Background and reason for feature request
I am creating a library that utilises chromedp and has it's own method of locating nodes for a QueryAction rather than using ByQuery, BySearch, etc.
Whilst I can pass my custom type into the sel of any QueryAction and create my own QueryOption (named byLocator in my case), I cannot connect the two as the Selector only has private fields and no getters.
I have a workaround but it is inelegant and not idiomatic to chromedp.
Example workaround
I'm currently doing something like this (abbreviated with no error handling).
# QueryAction uses nil selector and function to return QueryOption
chromedp.Click(nil, byLocator(myLocator))
#
func byLocator(sel Locator) chromedp.QueryOption {
return chromedp.ByFunc(func(ctx context.Context, n *cdp.Node) ([]cdp.NodeID, error) {
return []cdp.NodeID{myLocator.magicToGetNode()}, nil
}
}Example utilising requested feature
Using the requested feature eliminates the nil value for sel and allows me to specifiy a QueryOption rather than a function that returns one. The QueryAction just "looks right" in comparison to the above.
# QueryAction uses custom type as selector and uses an actual QueryOption
chromedp.Click(myLocator, byLocator)
#
func byLocator(s *Selector) {
myLocator := s.Sel().(Locator)
chromedp.ByFunc(func(ctx context.Context, n *cdp.Node) ([]cdp.NodeID, error) {
return []cdp.NodeID{myLocator.magicToGetNode()}, nil
}(s)
}Source: chromedp/chromedp