خرید بک لینک

Vote count: 0

I'm trying to make sure that in a "text box" I can only input specific characters , and or only numbers. I want to to this with selenium , but I seem unable to reach the script throw selenium. Im able to check the properties of the text box but not the script itself , since this one does not appear on screen.

Here is the code I want to check. How can I test the script through selenium?

<html>
    <head>
        <title>Simple form</title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>        

        <meta name="mobile-web-app-capable" content="yes">
        <meta charset="utf-8">
    </head>

    <body>
        <div>
            <form onsubmit="retu Validted()">
                New user registration:<br><br>
                <table>
                    <tr>
                        <td>
                            First name: *
                        </td>
                        <td>
                            <input type="text"  id="f_name"     name="fname"  maxlength="128" value="" class="firstn"  placeholder="first name" style="border-color: gray"><br>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Last name:  *
                        </td>
                        <td>
                            <input type="text"  id="l_name"     name="lname"  maxlength="128" value="" class="lastn"   placeholder="last name"  style="border-color: gray"><br>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Password:   *
                        </td>
                        <td>
                            <input type="password"  id="pass"   name="pass"   maxlength="128" value="" class="pass"    placeholder="password"  style="border-color: gray"><br>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Phone:      *
                        </td>
                        <td>
                            <input type="tel"   id="tel"        name="tel"    maxlength="15"  value="" class="phone"   placeholder="phone number"  style="border-color: gray"><br>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            E-mail:     *
                        </td>
                        <td>
                            <input type="email" id="user_email" name="email"  maxlength="128" value="" class="eml"     placeholder="Enter email"  style="border-color: gray"><br>
                        </td>
                    </tr>
                </table>
                <input type="submit" value="Register">
            </form>
        </div>

        <br>password rules: <br>
        only 0-9a-zA-Z         <br>
        at least 8 characters <br>
        at least 1 number <br>
        at least 1 lowercase character (a-z) <br>
        at least 1 uppercase character (A-Z) <br>


        <script>
            var validEmail = /^w+([-+.']w+)*@w+([-.]w+)*.w+([-.]w+)*$/;
            var validPhone = /(?([0-9]{3}))?([ .-]?)([0-9]{3})2([0-9]{4})/;
            var validPass = /^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])([a-zA-Z0-9]{8})$/;
            function testThis(what, reg, fld) {
                if (reg.test(what)) {
                    $('.' + fld).css('color', 'green');
                    console.log(fld);
                    retu true;
                }
                else {
                    $('.' + fld).css('color', 'red');
                    retu false;
                }
            }

            function Validted() {
                $('.pass').css('border-color', 'gray');
                $('.phone').css('border-color', 'gray');
                $('.eml').css('border-color', 'gray');

                if (!testThis($('#user_email').val(), validEmail, 'eml')) {
                    $('.eml').css('border-color', 'red');
                    retu false;
                }
                if (!testThis($('#pass').val(), validPass, 'pass')) {
                    $('.pass').css('border-color', 'red');
                    retu false;
                }
                if (!testThis($('#tel').val(), validPhone, 'phon')) {
                    $('.phone').css('border-color', 'red');
                    retu false;
                }

                retu true;
            }

            function validatePass() {
                $('#pass').keyup(function () {
                    retu testThis(this.value, validPass, 'pass');
                });
            }
         }

asked 3 mins ago

برچسب: نویسنده: استخدام کار تاريخ: يکشنبه 5 ارديبهشت 1395 ساعت: 17:23

صفحه بندی