Issue
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
Solution
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
Answered By - undetected Selenium
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.