I am trying to select a drop down menu and choose an option. I am using the latest version of Selenium, the latest version of Firefox, the latest version of geckodriver, and the latest version of Python.
Here is my issue: When I try to choose an option, it gives me the following error:
selenium.common.exceptions.ElementNotInteractableException: Message: Element <option> could not be scrolled into view.
I have tried various ways to circumnavigate this issue, but none seem to work. Here are some of the approaches I tried.
mySelectElement = browser.find_element_by_id('providerTypeDropDown')
dropDownMenu = Select(mySelectElement)
dropDownMenu.select_by_visible_text('Professional')
mySelectElement = browser.find_element_by_id('providerTypeDropDown')
dropDown = Select(mySelectElement)
for option in dropDown.options:
message = option.get_attribute('innerText')
print(message)
if message == 'Professional':
print("Exists")
dropDown.select_by_visible_text(message)
break
element = browser.find_element_by_id('providerTypeDropDown')
browser.execute_script("var select = arguments[0]; for(var i = 0; i < select.options.length; i++){ if(select.options[i].text == arguments[1]){ select.options[i].selected = true; } }", element, "Professional")
The HTML code follows the usual select tags and option tags. Any help is appreciated. The HTML code is included below.
<select data-av-chosen="providerTypes" id="providerTypeDropDown" data-placeholder="Please Select a Provider Type" name="providerTypeDropDown"
class="chzn-select input-full ng-pristine chzn-done ng-invalid ng-invalid-provider-type" data-ng-options="providerType.value for providerType in request.models.providerTypes"
data-ng-model="request.models.providerType" data-av-validator-field="providerType" data-disable-search-threshold="5" style="display; none;">
<option value="" class="">Please Select a Provider Type</option>
<option value="0">Professional</option>
<option value="1">Institutional</option>
</select>
The print statements are there for testing/code tracing purposed.
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…