I am trying to write a test for my application but it is currently failing. I'm not sure what the problem is but I have tried it with an WebDriverWait
and even a time.sleep()
but this has not solved the problem.
The failing part of the test looks like this:
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.
What should happen is that the element is clicked and then a new element is inserted into the DOM
. But as the assertion is failing this clearly isn't happening. I have also done a print(self.driver.page_source)
after the click and I can see that the element isn't being added so for some reason the click isn't being registered.
I thought that it may be due some custom jQuery scripts not being finished before the test takes place on the page but I added this:
def wait_script(self):
WebDriverWait(self.driver, 10).until(lambda s: s.execute_script("return jQuery.active == 0"))
after the page change and it returns True
before the test begins, so I assume that means that all jQuery
processes are complete, unless this doesn't take into account page specific custom functions?
Any help with this conundrum would be much appreciated.