0

I'm trying to select an element from a dropdown but getting an error.

Here is the HTML:

<select id="childContextDDL" data-filter="contains" data-role="dropdownlist" data-template="dcf-context-picker" data-value-field="Value" data-text-field="DisplayText" data-bind="events: { change: childContextListChange }, source: childContextList.ChildContextList" style="display: none;">
<option value="1">NATION</option>
<option value="12">ATLANTIC</option>
<option value="16">CHARLOTTE, NC</option>

And this is the code that I'm trying to run:

mySelect = Select(driver.find_element_by_id("childContextDDL"))
print('MySelect is: ',mySelect)
mySelect.select_by_visible_text('ATLANTIC')

I'm getting this error:

selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable: Element is not currently visible and may not be manipulated

What's the possible reason for getting this error? I'm very new to Selenium.

I also want to click on that element after selecting it.

5

3 Answers 3

1

The problem was that the style within the html was set to none. So I had to first change that style to block to make it visible and then proceed with the clicking operation.

Here's the code that worked:

driver.execute_script("document.getElementById('childContextDDL').style.display = 'block';")

mySelect = Select(driver.find_element_by_id("childContextDDL"))
print('MySelect is: ',mySelect)
mySelect.select_by_visible_text('ATLANTIC')

randomClick = driver.find_element_by_id('dcf-user-info')
randomClick.click()
Sign up to request clarification or add additional context in comments.

Comments

0

I guess the mySelect element (the dropdown menu) is not visible.
So please try the following:

from selenium.webdriver.common.action_chains import ActionChains
actions = ActionChains(driver)

mySelect = Select(driver.find_element_by_id("childContextDDL"))

actions.move_to_element(mySelect).perform()
mySelect.select_by_visible_text('ATLANTIC')

If the above doesn't work (I can't see the actual site you are working on), the following can work instead in the element has to be tapped to become enabled

action = TouchActions(driver)
action.tap(mySelect).perform()
mySelect.select_by_visible_text('ATLANTIC')

13 Comments

For the 1st piece of code, I'm getting this error: AttributeError: move_to requires a WebElement
For the 2nd piece of code, I'm getting this error: AttributeError: 'Select' object has no attribute 'id'
This is what YOU wrote. I have no idea how to locate that element
Haha it was still within the HTML code that I had posted but it was at the end. Anyway, it's fine, thanks for trying to help me out, really appreciate it!
I've asked 1 more question. If you have time, it will be helpful if you can look into it: stackoverflow.com/questions/67784552/…
|
0

If it says it is not currently visible, you should try pausing the code with one of this options:

time.sleep(1) #This states to your code to stop for 1 second and the continue with the work.
WebDriverWait(driver, 10).until(EC.element_to_be_visible(BY.value, "12")) # tells the driver to wait a maximum of ten seconds until the value "12" is visible for the driver.

8 Comments

Can you please fill in the blanks for my code, it'll be really helpful. I'm finding the syntax of that confusing for now
Edited! Tell me if it works just with this :)
The problem is that the element is present but not visible when the interaction is attempted. So I don't see how waiting for the presence will help. Perhaps you should use EC.element_to_be_visible()?
Yes, it is more logical your argument.
Should this be before 'mySelect'? Because I tried that and now getting this error: AttributeError: type object 'By' has no attribute 'value'
|

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.