Using ToGPALObject() at the end of a chain and casting the result explicitly to the concrete type are two ways to do the same thing. Each With... Call in the chain returns a configuration interface that only exposes more With... Methods -- it is not the finished object. ToGPALObject() or an explicit cast is what converts that configuration into the real, usable object with all of its members available.
// These two lines are equivalent
Selector sel1 = GPAL
Selector sel1 = (Selector)GPAL
If you stop at GPAL.Selector.WithCSS("#username") without ToGPALObject() or a cast, the result is still just the configuration interface. Var sel1 = GPAL.Selector.WithCSS("#username"); compiles, but sel1's type only offers more With... Methods. Calling sel1.Remove() on it will not compile. ToGPALObject() or a cast is what gets you the rest of the object's API.
When declaring a variable, ToGPALObject() is usually easier. IntelliSense offers it right at the end of the chain with no need to remember the exact type name. When passing a chain inline as an argument, an explicit cast can read cleaner: the type name up front signals what is being handed over without a trailing ToGPALObject() at the end of a long chain.
// Inline argument - explicit cast reads cleanly
GPAL
// Same control, written with ToGPALObject() instead
GPAL
GPAL doesn't enforce either style. Both compile to the same thing. Pick based on what reads best for that line: ToGPALObject() while writing a chain top to bottom, an explicit cast when the chain is just one argument among several.
When you only need to store a reference to call methods on later -- and you do not need compile-time type checking on that variable -- declaring it as dynamic sidesteps the need for ToGPALObject() or an explicit cast entirely. The assignment resolves at runtime and every method call on the dynamic variable dispatches to the actual underlying object. This works well for browser or application references stored as fields and called from event handlers. It does not work for form controls, where you need the concrete typed field to pass to WithFormControl and other typed parameters.
// dynamic: no ToGPALObject or cast needed, resolved at runtime
static dynamic browser { get; set; }
browser = GPAL
// later, in another handler:
browser?
// For controls, you still need the concrete type --
// WithFormControl requires GPALButton, not dynamic
static GPALButton saveBtn = GPAL
Use dynamic when you need to store a GPAL object reference and call methods on it later, but the exact return type is inconvenient to spell out or changes across calls. Use ToGPALObject() or an explicit cast when you need the typed API -- for passing to WithFormControl, for IntelliSense on the variable, or when the type will be inspected at compile time.
Showing off some plain text in these paragraphs eligendi laboriosam illo nostrum corporis at libero vel voluptas? Expedita, facere dolores voluptatem ad ab rem assumenda soluta!
Lorem ipsum dolor sit amet consectetur adipisicing elit. Obcaecati, iste distinctio veritatis eligendi laboriosam illo nostrum corporis at libero vel voluptas? Expedita, facere dolores voluptatem ad ab rem assumenda soluta!
Lorem ipsum dolor sit amet consectetur adipisicing elit. Obcaecati, iste distinctio veritatis eligendi laboriosam illo nostrum corporis at libero vel voluptas? Expedita, facere dolores voluptatem ad ab rem assumenda soluta!
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quo veniam mollitia excepturi animi eum illum non libero sapiente provident assumenda, delectus voluptatum nobis sed dolorem adipisci laudantium incidunt. Error, ratione?
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quo veniam mollitia excepturi animi eum illum non libero sapiente provident assumenda, delectus voluptatum nobis sed dolorem adipisci laudantium incidunt. Error, ratione?
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quo veniam mollitia excepturi animi eum illum non libero sapiente provident assumenda, delectus voluptatum nobis sed dolorem adipisci laudantium incidunt. Error, ratione?
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quo veniam mollitia excepturi animi eum illum non libero sapiente provident assumenda, delectus voluptatum nobis sed dolorem adipisci laudantium incidunt. Error, ratione?
Here you can find different accents and emphasis sit amet consectetur adipisicing elit. Obcaecati, iste distinctio veritatis eligendi laboriosam illo nostrum corporis at libero vel voluptas? Expedita, facere dolores voluptatem ad ab rem assumenda soluta!
This is a link and how it could look like bestlinkinthebeautifulworld. Obcaecati, iste distinctio veritatis eligendi laboriosam illo nostrum corporis at libero vel voluptas? Expedita, facere dolores voluptatem ad ab rem assumenda soluta!
Here's just some classic bold text adipisicing elit. Obcaecati, iste distinctio veritatis eligendi laboriosam notBoldSecondbestlinkinthebeautifulworld illo nostrum corporis at libero vel voluptas? Expedita, facere dolores voluptatem ad ab rem assumenda soluta!
Obcaecati, iste distinctio veritatis eligendi laboriosam adipisicing elit illo nostrum corporis at adipisicing elit libero vel voluptas? Expedita, adipisicing facere dolores voluptatem ad ab rem assumenda soluta!
Other cuple of colors in case we want to emphasize several ways adipisicing elit. Obcaecati, iste distinctio veritatis eligendi laboriosam adipisicing elit illo nostrum corporis at voluptatem libero vel voluptas? Expedita, facere dolores voluptatem ad ab rem assumenda soluta!
Lorem ipsum dolor sit amet consectetur adipisicing elit. Obcaecati, iste distinctio veritatis eligendi laboriosam illo nostrum corporis at libero vel voluptas? Expedita, facere dolores voluptatem ad ab rem assumenda soluta! Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quod veniam, quam ad expedita laborum sed at voluptates culpa ipsam ut vel. Ullam temporibus a mollitia quod aliquam ratione exercitationem nesciunt.
Lorem ipsum dolor sit amet consectetur adipisicing elit. Obcaecati, iste distinctio veritatis eligendi laboriosam illo nostrum corporis at libero vel voluptas? Expedita, facere dolores voluptatem ad ab rem assumenda soluta! Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quod veniam, quam ad expedita laborum sed at voluptates culpa ipsam ut vel. Ullam temporibus a mollitia quod aliquam ratione exercitationem nesciunt.
Lorem ipsum dolor sit amet consectetur adipisicing elit. Obcaecati, iste distinctio veritatis eligendi laboriosam illo nostrum corporis at libero vel voluptas? Expedita, facere dolores voluptatem ad ab rem assumenda soluta!
Lorem ipsum dolor sit amet consectetur adipisicing elit. Repudiandae quas consequuntur illo numquam assumenda autem exercitationem distinctio perspiciatis in natus. Eius dicta similique ipsam ipsa minima, nemo quae enim tempore.
GPAL
.CallIfNotFound(GenericCallIfNotFound)
.WithPublishToConsole();
//System.Drawing.Rectangle windowSize = new System.Drawing.Rectangle(10, 10, 1500, 1024);
// NOTE: we have to set browser = before we execute any steps
// this is due to the 'GenericCallIfNotFound' which might throw an exception, and BankScraper will not have the browser set when it calls scraper.Close()
// until the complete fluent line gets executed (meaning every step, meaning browser is not set until everything else succeeds)
browser = GPAL.Browser
.WithBrowserType(Enums.BrowserType.Chrome)
.WithProfileDataDirectory(ChromeProfileLocation)
.WithUseAutomationEngine(AutomationEngine.Selenium)
.WithWindowSize(new System.Drawing.Rectangle(0,0,1920,1080))
.ToGPALObject();