Try-except doesn't work as intended (failing my try on purpes but it doesnt do the except)

87 Views Asked by At

I have this code:

            try:
                self.send_keys(fn.FieldsNames.event_html, fn.FieldsNames.position_change)
                self.click(f"//*[contains(text(),'{fn.FieldsNames.position_change}')]")
                f.Functions.wait_for_loading(self)
                self.send_keys(fn.FieldsNames.event_reason_html_job_info, fn.FieldsNames.department_change)
                self.click(f"//*[contains(text(),'{fn.FieldsNames.department_change}')]")
                self.clear(fn.FieldsNames.department_html)
                self.send_keys(fn.FieldsNames.department_html, "random_department")
                self.sleep(2)
                self.click(f"//*[contains(text(),'{random_department}')]")
                f.Functions.wait_for_loading(self)
                old_department = self.get_text(fn.FieldsNames.old_department_value_html)
                self.click(f"//*[contains(text(),'{fn.FieldsNames.save}')]")
                self.wait_for_element_absent(f"//*[contains(text(),'{fn.FieldsNames.save}')]")
                self.refresh()
            except:
                self.refresh()
            else:
                self.refresh()

and I fail on purpes this line

self.send_keys(fn.FieldsNames.department_html, random_department)

instead of random_department I wrote "fail test" but my code doesn't fail (or raising exception) so it kinda passes above the except and continues to run the code. what could be the problem? Can you give me suggestions on how to write this code more efficiently.

0

There are 0 best solutions below