I'm currently facing an issue when writing a test for my application as it continues to fail. Despite attempting to use both WebDriverWait
and time.sleep()
, the problem persists.
The troublesome section of the test appears as follows:
form_2.find_element_by_css_selector('.btn-primary').click() # submits form_2 and changes page to next form
self.assertEqual(
self.get_current_url(),
self.live_server_url + reverse(
'activitygroupconfigstepkeycharacteristicfieldset_update', kwargs={'activitygroupconfig_pk': 1}
)
) # test to see if expected url is correct
# Fill out next form (i.e. Key Characteristics)
form_3 = self.driver.find_element_by_xpath('//form[@role="form"]')
form_3.find_element_by_css_selector(
'#div_id_activitygroupconfigstepkeycharacteristicfield_set-0-key_characteristic'
).click()
assert form_3.find_element_by_css_selector('.select2-container--open').is_displayed() is True # I'm getting this error: selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".select2-container--open"} here so the click clearly isn't working.
The desired outcome is that the element gets clicked, triggering the insertion of a new element into the DOM
. However, the assertion failure indicates that this process isn't happening as expected. Following the click action, I also checked with print(self.driver.page_source)
and it showed that the element was not added, suggesting that the click event wasn't being recognized.
My initial thought was that the issue might be related to custom jQuery scripts not completing before the test engages on the page. To address this, I included the following:
def wait_script(self):
WebDriverWait(self.driver, 10).until(lambda s: s.execute_script("return jQuery.active == 0"))
After implementing this script post-page transition, verifying True
returned before commencing the test; hence, I presumed all relevant jQuery
operations had concluded, unless any potential page-specific customized functions were overlooked?
Your assistance in resolving this puzzle would be greatly valued.