'How can i locate toast Messages which is in same function for error and success via selenium/python?

I am facing an issue in python/selenium, in which I can't get, how to use Script for toast messages, that are in the same function. The function has the same locator. How can I use the same locator for two messages?

**Here is the javascript **

    }, function(data, status) {
                    if (data.status == "OK") {
                        if (data.statusCode == 1){
                            var message = data.response;
                            showToast(message);
                        } else {
                            var error = data.responseMessage;
                            swal(error, "", "error");
                        }
                    }else {
                        var error = data.response;
                        showToast(error);
                    }
                });
        });
        function showToast(content){
            $("#customtoast").addClass("display");
            $("#customtoast").html(content);
            setTimeout(function() {
                $("#customtoast").removeClass("display");
                location.reload();
            }, 2000);
        }
    

** Now I want to locate separately for error and for success via the selenium/python**

Here is my html code...

    <form class="new-added-form" id="addStudentForm">
    <div class="row">
        <div class="col-xl-3 col-lg-6 col-12 form-group">
            <div class="floating-label">
                <input class="floating-input" type="text" placeholder=" " name="firstname" id="firstname">
                <span class="highlight"></span>
                <label>First Name</label>
            </div>
        </div>
        <div class="col-xl-3 col-lg-6 col-12 form-group">
            <div class="floating-label">
                <input class="floating-input" type="text" placeholder=" " name="lastname" id="lastname">
                <span class="highlight"></span>
                <label>Last Name</label>
            </div>
        </div>
        <div class="col-xl-3 col-lg-6 col-12 form-group">
            <div class="floating-label">
                <input class="floating-input" type="text" placeholder=" " name="age" id="age">
                <span class="highlight"></span>
                <label>Age</label>
            </div>
        </div>
        
        <div class="col-xl-3 col-lg-6 col-12 form-group">
            <label>Date Of Birth *</label>
            <input type="date" class="form-control air-datepicker border-0" data-position='bottom right' name="dob" id="dob">
            <i class="far fa-calendar-alt"></i>
        </div>
        <div class="col-xl-3 col-lg-6 col-12 form-group">
            <div class="floating-label">
                <input class="floating-input" type="text" placeholder=" " name="email" id="email">
                <span class="highlight"></span>
                <label>Email</label>
            </div>
        </div>
           <div class="col-xl-3 col-lg-6 col-12 form-group">
            <div class="floating-label">
                <input class="floating-input" type="text" placeholder=" " name="permitno" id="permitno">
                <span class="highlight"></span>
                <label>Permit number</label>
            </div>
        </div>
           <div class="col-xl-3 col-lg-6 col-12 form-group">
            <div class="floating-label">
                <input class="floating-input" type="text" placeholder=" " name="nationality" id="nationality">
                <span class="highlight"></span>
                <label>Nationality</label>
            </div>
        </div>
          <div class="col-xl-3 col-lg-6 col-12 form-group">
            <div class="floating-label">
                <input class="floating-input" type="text" placeholder=" " name="phone" id="contactno" maxlength="10">
                <span class="highlight"></span>
                <label>Contact Number</label>
            </div>
        </div>
          <div class="col-xl-3 col-lg-6 col-12 form-group">
            <div class="floating-label">
                <input class="floating-input" type="text" placeholder=" " name="address" id="address">
                <span class="highlight"></span>
                <label>Address</label>
            </div>
        </div>
        
        <div class="col-12 form-group mg-t-8">
            <button type="button" class="btn-fill-lg btn-gradient-yellow btn-hover-bluedark" id="save">Save</button>
            <button type="reset" class="btn-fill-lg bg-blue-dark btn-hover-yellow">Reset</button>
        </div>
    </div>
</form>

<!-- Custom toast/ snackbar -->
<div id="customtoast"> </div>

I want to know the automation script for this.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source