I have a simple Python/Selenium script that has to wait for 4 checks to happen. Each of these on a separated thread. On the first thread that returns information, the program should continue and the remaining threads killed (if possible).
I have a program that is creating the threads just fine, but I have no idea on how to continue on the first that have executed.
these are my function definitions:
def wait_by(search_type, locator, timeout):
WebDriverWait(driver, timeout).until(EC.presence_of_element_located((search_type, locator)))
def multi_locator_verify_element(xpath_locator, css_locator, name_locator, id_locator, timeout):
element = ""
if xpath_locator != "":
tx = Thread(target=wait_by, args=(By.XPATH, xpath_locator, timeout))
tx.start()
if css_locator != "":
tc = Thread(target=wait_by, args=(By.CSS, css_locator, timeout))
tc.start()
if name_locator != "":
tn = Thread(target=wait_by, args=(By.NAME, name_locator, timeout))
tn.start()
if id_locator != "":
ti = Thread(target=wait_by, args=(By.ID, id_locator, timeout))
ti.start()
The multi_locator_verify_element function should finish after the first thread has been able to retrive the right element.
Could someone please help me with that?
Regards,