DEV Community

Discussion on: Using Selenium with Rust

Collapse
 
gomez profile image
gomez • Edited

Hello Steve,

So I have a similar question to the one above. Lets say we have a dropdown. For example lets take this checkout page I found:

(Apologies for the '--' included in the tags. I wasn't sure exactly how to post html here directly. It kept displaying it normally without any of the html syntax)

<--select class="select optional" name="order_billing_state" id="order_billing_state" aria-invalid="false">
<--option value="AL">AL
<--option value="AK">AK
<--option value="AS">AS
<--option value="AZ">AZ
<--/select>

-- Currently I have it set to target the element by the ID. But i'm not sure exactly how to target those elements enclosed in the tag. Any ideas?

let elem_order_billing_state = driver.find_element(By::Name("order_billing_state")).await?;

Collapse
 
stevepryde profile image
Steve Pryde

You can target them directly using xpath "option[text()='AK']" (or you can match on the value instead of the text if preferred).

It may be possible to just click the option directly but if not then just click the select element first then the option.

Alternatively the CSS selector can also work e.g. "option[value='AK']"

These questions are really general selenium questions not specific to thirtyfour or Rust. The same will apply using any selenium framework or library. As I mentioned some libraries do provide a wrapper for select elements specifically but it's just doing the above for you.