0

I am attempting to select an item from a drop-down element using Selenium but the only unique ID is in the data-bind value. I have tried using

<select data-bind="value: customerProvince, options: availableProvinces, optionsText: 'Name', optionsCaption: ''" class="form-control uc-not-searchable" size="1">
<option value=""></option><option value="">Alberta</option><option value="">British Columbia</option><option value="">Manitoba</option><option value="">New Brunswick</option><option value="">Newfoundland and Labrador</option><option value="">Northwest Territories</option><option value="">Nova Scotia</option><option value="">Nunavut</option><option value="">Ontario</option><option value="">Prince Edward Island</option><option value="">Quebec</option><option value="">Saskatchewan</option><option value="">Yukon Territory</option>
                        </select>

I would then like to select an option value. I have tried both pieces of the following code to no avail:

customerProvinceField = browser.find_element_by_css_selector("value: customerProvince, options: availableProvinces, optionsText: 'Name', optionsCaption: ''")

customerProvinceField = browser.find_element_by_css_selector("value: customerProvince")

Both receive an error of: "Message: invalid selector: An invalid or illegal selector was specified".

2

1 Answer 1

0

Use below :-

customerProvinceField= driver.find_element_by_xpath('//select[contains(@data-bind,"value: customerProvince, options: availableProvinces, optionsText:")]')

Code will be like

Select(driver.find_element_by_xpath('//select[contains(@data-bind,"value: customerProvince, options: availableProvinces, optionsText:")]')).select_by_value('Nunavut').click()

refer :-

Selecting a value from a drop-down option using selenium python

Hope it will help you

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.