1

I have a form that I fill with some data and everything is OK till I tried to click on Submit button. It doesn't respond at all Here's the outHTML of the element

<input type="submit" class="btn btn-primary commandButton" value="إرسال  الطلــب" id="cmdSubmit">

I tried these lines

.ExecuteScript "arguments[0].click();", .FindElementByCss("#cmdSubmit")

I even tried byID and byXPATH and nothing worked with the element

While inspecting the webpage, I have searched for submit and I think I found related function

<script>
            $('#frmExecReq').submit(function(){ // catch form submit event
            
                if($('#selectAsed').val() <= 0){
                    $('#selectAsedWarninig').show();
                    return false;
                }
                
                         
                        if(!$.isNumeric($('#phoneNo').val())){
                    $('#phoneNoWarninig').show();
                    return false;
                }
                        
                        
                         var mobileNumber = document.getElementById("phoneNo").value;
                    var mobileLength = mobileNumber.length;
                    var checkFirstNumber = mobileNumber.substring(0, 1);
                    if(mobileNumber ==""){
                                        document.getElementById('phoneNoWarninig').style.display = 'inline';
                        document.getElementById('phoneNo').focus();
                                        document.getElementById('phoneNo').select();
                        return false;
                    }else if( mobileLength !=8 ){
                                        document.getElementById('phoneNoWarninig').style.display = 'inline';
                        document.getElementById('phoneNo').focus();
                                        document.getElementById('phoneNo').select();
                        return false;
                    }else if(checkFirstNumber != 5 && checkFirstNumber != 6 && checkFirstNumber != 9){
                                        document.getElementById('phoneNoWarninig').style.display = 'inline';
                        document.getElementById('phoneNo').focus();
                                        document.getElementById('phoneNo').select();
                        
                        return false;
                    }
                        
                        
                if($('#txtReceivedSum').length){
                    if(!$.isNumeric($('#txtReceivedSum').val())){
                        $('#txtReceivedSumWarninig').show();
                        return false;
                    }
                }
                        //////////
                        
                        var trnCodeNum = document.getElementById("trnCodeNum").value;
                        var persType = document.getElementById("persType").value;
                        if( (trnCodeNum == 0815 && persType == 2) || (trnCodeNum == 0875 && persType == 2) ||  (trnCodeNum == 0820 && persType == 1)
                                || trnCodeNum == 0810 || trnCodeNum == 0825){ 
                                                    
                            var y = document.getElementById('attachments');
                                if ('files' in y) {
                                    if (y.files.length == 0) {
                                        document.getElementById('reqWarning2-1').style.display = 'inline';
                                        //$('#sreqFile1Warning1').show();
                                        return false;
                                    } else {
                                        var file = y.files[0];
                                        if ('name' in file) {
                                            var n = file.name;
                                            fileExtension = n.split('.').pop();

                                            if (!(fileExtension == "pdf")) {
                                                $('#reqWarning2-2').show();
                                                return false;
                                            }
                                            if ('size' in file) {
                                                if (file.size > 10485762) { //10 MB
                                                    $('#reqWarning2-3').show();
                                                    return false;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        ///////////
                        
                        var form = $('#frmExecReq')[0];
                            // Create an FormData object 
                        var data = new FormData(form)
                
                $.ajax({ // create ajax call
                    data: data, //get form data
                                //contentType: 'multipart/form-data',
                                processData: false,
                                contentType: false,
                                method: 'POST',
                    type: $(this).attr('method'), //GET or POST
                    url: $(this).attr('action'), // the action url
                    success: function(response){ // on success
                        $('#viewPaneChildDetails').html(response); //update DIV
                        $('#viewPaneChild').hide();
                        $('#viewPaneChildDetails').show();
                    }
                });
                return false; // cancel original event to prevent form submitting 
            });
        </script>

When trying this line, an error occurred

.FindElementByXPath("//input[@class='btn btn-primary commandButton' and @id=='dSubmit'][@vlaue='إرسال  الطلــب']").Click

enter image description here

2
  • That's not Python that you're executing... Commented Apr 19, 2022 at 20:26
  • I have updated the tags. Thanks a lot. Commented Apr 19, 2022 at 20:28

1 Answer 1

1

To click on the element you can use either of the following locator strategies:

  • Using FindElementByCss:

    .FindElementByCss("input.btn.btn-primary.commandButton#cmdSubmit").click
    
  • Using FindElementByXPath:

    .FindElementByXPath("//input[@class='btn btn-primary commandButton' and @id='cmdSubmit']").click
    
Sign up to request clarification or add additional context in comments.

9 Comments

Thanks a lot, but when trying the line, an error occurred. I have updated the question to insert a picture of the error.
Removed the value attribute, possibly I was pasting incorrectly. Please retest.
The same error again. It seems this button is related to javascript function that works in specific way but I didn't experience such a problem before.
The error must be different now, it shouldn't be InvalidSelectorError like before.
As for the css selector, I got Element Not Found but as for xpath the same error as attached in the picture in the question
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.