I'm building a Selenium Chrome bot using Python. I implement python coroutine a sync function. Using Selenium wait method with python a sync function.
I got an error which behavior is not what I expect.
I select item on drop-down A, wait for few seconds, so that drop-down B will be populated based on item's value in drop-down A.
This process wraps inside python a sync function with await. It doesn't loop according to this behavior.
But run all at once.
async def
regionLists = ['111','222','333']
regionElem = self.browser.find_element_by_id("regionId")
regionSelect = Select(regionElem)
regionTasks = [
self.parseCities(self.browser, regionSelect, regionValue)
for regionValue in regionLists
]
result = await asyncio.wait(regionTasks)
ParseCities function
async def parseCities(self, browser, regionSelect, regionValue):
regionSelect.select_by_value(regionValue)
# ERROR AT THIS LINE BELOW
wait(browser, 10).until(
lambda b: len(Select(b.find_element_by_id("cityId")).options) > 1
)
Error
Task exception was never retrieved
future: <Task finished coro=<main.parseCities() done, defined at Selenium/main.py:139> exception=NoSuchElementException('Cannot locate option with value: 781111')>
Traceback (most recent call last):
File "Selenium/main.py", line 140, in parseCities
regionSelect.select_by_value(regionValue)
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/support/select.py", line 87, in select_by_value
raise NoSuchElementException("Cannot locate option with value: %s" % value)
selenium.common.exceptions.NoSuchElementException: Message: Cannot locate option with value: 781111