When interacting with form elements you may be interested in doing more than checking a box or entering text into a field. For scenarios where you’d like to select a value from a dropdown, the CHOOSE keyword can be helpful.
FROM url
|> CHOOSE IN <css_selector> "<value_to_choose>"
|> SELECT value
When selecting a known exact value from a multiselect element, then you may be interested in CHOOSEing IN that particular element.
|> CHOOSE IN <css_selector> "<value_to_choose>"
For an example, see below.
When selecting for a value that may or not match the input but you want to do so fuzzily then when selecting a value in the multiselect you want to CHOOSE but in a FUZZY way.
|> CHOOSE FUZZY <css_selector> "<value_to_fuzzily_match_against>"
It derives the best option to select by Levenshtein distance.
Let’s take this website with pricing calculators by Smooth-On and suppose we’d like to have a way to programmatically obtain the calculated value for the Pour On Mould Estimator (click here if you’d like to skip to the final code).
The first step would be to establish the page we’re working from so the SQL you’d be looking for is:
calculators <| https://www.smooth-on.com/support/calculators/ |
FROM calculators
Next, we need to trigger the calculation wizard to pop up by clicking on the link corresponding to it.
calculators <| https://www.smooth-on.com/support/calculators/ |
pour_on_mold <| div[data-calcid="pour-mold"] |
FROM calculators
|> CLICK ON pour_on_mold
Once the modal’s opened up we need to choose the value we’re interested in. You can find the value of the field you’re looking for by opening Inspect Element and using the value attribute of the you’re interested in.
calculators <| https://www.smooth-on.com/support/calculators/ |
pour_on_mold <| div[data-calcid="pour-mold"] |
product_dropdown <| #pour-prod |
dropdown_value <| "24.7" |
FROM calculators
|> CLICK ON pour_on_mold
|> CHOOSE IN product_dropdown dropdown_value
Here you can either hard set the value you’d like to calculate for or string template them in a postgres adapter when you ENTER the respective volumes.
calculators <| https://www.smooth-on.com/support/calculators/ |
pour_on_mold <| div[data-calcid="pour-mold"] |
product_dropdown <| #pour-prod |
dropdown_value <| "24.7" |
model_volume_input <| #pour-model-volume |
model_volume <| "12" |
box_volume_input <| #pour-box-volume |
box_volume <| "20" |
FROM calculators
|> CLICK ON pour_on_mold
|> CHOOSE IN product_dropdown dropdown_value
|> ENTER INTO model_volume_input model_volume
|> ENTER INTO box_volume_input box_volume
After the values have been filled out the last thing we need to do is actually submit so we can receive an estimate back.
calculators <| https://www.smooth-on.com/support/calculators/ |
pour_on_mold <| div[data-calcid="pour-mold"] |
product_dropdown <| #pour-prod |
dropdown_value <| "24.7" |
model_volume_input <| #pour-model-volume |
model_volume <| "12" |
box_volume_input <| #pour-box-volume |
box_volume <| "20" |
calculate_button <| #pour-calculate |
FROM calculators
|> CLICK ON pour_on_mold
|> CHOOSE IN product_dropdown dropdown_value
|> ENTER INTO model_volume_input model_volume
|> ENTER INTO box_volume_input box_volume
|> CLICK ON calculate_button
If you’d like to not just run the calculation but also select the estimate at the end, that’s just a matter of SELECTing it!
calculators <| https://www.smooth-on.com/support/calculators/ |
pour_on_mold <| div[data-calcid="pour-mold"] |
product_dropdown <| #pour-prod |
dropdown_value <| "24.7" |
model_volume_input <| #pour-model-volume |
model_volume <| "12" |
box_volume_input <| #pour-box-volume |
box_volume <| "20" |
calculate_button <| #pour-calculate |
estimate <| #pour-results |
FROM calculators
|> CLICK ON pour_on_mold
|> CHOOSE IN product_dropdown dropdown_value
|> ENTER INTO model_volume_input model_volume
|> ENTER INTO box_volume_input box_volume
|> CLICK ON calculate_button
|> SELECT estimate
For the above SQL statement with without variable assignments, here’s what that looks like.
FROM https://www.smooth-on.com/support/calculators/
|> CLICK ON div[data-calcid="pour-mold"]
|> CHOOSE IN #pour-prod "24.7"
|> ENTER INTO #pour-model-volume "12"
|> ENTER INTO #pour-box-volume "20"
|> CLICK ON #pour-calculate
|> SELECT #pour-results AS estimate