So I've been working on some automation with selenium and decided to throw in a loop to go over a list of parties stored in an array. The for loop searches up the parties and clicks on a element that displays the parties information then returns back to the search bar and loops again.
During the first iteration, everything works as expected. But my problem is during the second iteration I am unable to find the element to click on the element after the search has been successful. I guess it might have been related to the Iframe but I am not convinced. Maybe there is something wrong with my code that I am unaware of but your help would be much appreciated :)
Don't mind the sleep function, I am just using it for the time being (will switch to explicit waits after all functionality works)
Just to provide more insight: If I were to start the loop at any index of the array, the first loop will always succeed, meaning that finding the element by title works for each party.
for x in range(0, party_length):
CRM_driver.find_element_by_xpath("(.//*[normalize-space(text()) and normalize-space(.)='Cases'])[1]/following::span[6]").click()
CRM_driver.find_element_by_id("search").click()
CRM_driver.find_element_by_id("search").clear()
CRM_driver.find_element_by_id("search").send_keys(party[x].party_name)
time.sleep(2)
CRM_driver.find_element_by_xpath('//*[@id="findCriteriaButton"]').click()
# Changes the iFrame to inspect CRM elements
time.sleep(5)
iFrame = CRM_driver.find_element_by_xpath('//*[@id="contentIFrame1"]')
CRM_driver.switch_to.frame(iFrame)
print(iFrame)
CRM_driver.find_element_by_xpath('//*[@title = "' + party[x].party_name + '"]').click()
#returns to default IFrame and main page
CRM_driver.switch_to.default_content()
CRM_driver.find_element_by_id('navTabLogoTextId').click()
time.sleep(2)
Expected: Search is successful -> able to click on element to display party status -> return to main screen -> repeat
Actual Result: Search is successful -> Unable to locate element (On second iteration)