Our web application contain certain fields such as transaction date, complaint date where we need to choose the date from the calendar option and we cannot enter the field value manually. I have attached the screens. I understand the date pick topic was already discussed and based on that I tried some scripting in katalon that also attached.
This line executes a javascript, but I see you are passing Katalon Test Object’s ID which the page will not understand ( Javascript is executed by the browser on the web page ). This is why the Exception says that it cannot read remoteAttr (the function) because the previous code segment is executed and returns null.
From the content of the Test Object you posted, I suggest modify it to something like:
Reason:
groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.executeJavaScript() is applicable for argument types: (java.lang.String) values: [document.getElementById(‘ComplaintSubview:ComplaintForm:j_id_jsp_2028274554_63pc16InputDate’).removeAttr(‘readonly’)]
Possible solutions: executeJavaScript(java.lang.String, java.util.List), executeJavaScript(java.lang.String, java.util.List, com.kms.katalon.core.model.FailureHandling)
at Reactive disputes - TC-003-transaction date.run(Reactive disputes - TC-003-transaction date:46)
at
Please use the following revised line: WebUI.executeJavaScript(“document.getElementById('ComplaintSubview:ComplaintForm:j_id_jsp_2028274554_63pc16InputDate').removeAttr('readonly')”, null)
I faced another error after trying that commnad as below:
(Root cause: org.openqa.selenium.WebDriverException: unknown error: document.getElementById(…).removeAttr is not a function
Then i tried with “removeAttribute” instead of “removeAttr” and it was successful and the java script executed fine. my next step was to set the text as 11/01/2015 for the date field. when i tried that using the script:
com.kms.katalon.core.exception.StepFailedException: Unable to set text ‘11/01/2015’ of object ‘Object Repository/new spy/Page_eSDMS - Neethu/input_Transaction From_Complai’ (Root cause: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Object Repository/new spy/Page_eSDMS - Neethu/input_Transaction From_Complai’ located by ‘By.xpath: //input[@class = ‘rich-calendar-input’ and @id = ‘ComplaintSubview:ComplaintForm:j_id_jsp_2028274554_63pc16InputDate’ and @name = ‘ComplaintSubview:ComplaintForm:j_id_jsp_2028274554_63pc16InputDate’ and @type = ‘text’ and @readonly = ‘readonly’]’ not found)
at com.kms.katalon.core.keyword.internal.KeywordMain.stepFailed(KeywordMain.groovy:36)
Yes, the exception indicates that the element was not found by the above XPath.
From the XPath above I suspect you are using Attributes -based locators. Please go to the test object that was unable to be located and select XPath radio button, hit save and then re-run the test again. Additionally, you may copy and paste other XPaths into the XPath selector to see if one of the XPaths resolve this issue.
i found a challenge with my object input_Transaction From_Complai’. By default the calender will set current date. So the object that i captured yesterday was having the element id ComplaintSubview:ComplaintForm:j_id_jsp_2028274554_63pc16InputDate and when i tried to run the test today, i got error as web element not found
i captured the object again, and now the id is: ComplaintSubview:ComplaintForm:j_id_jsp_255849347_63pc16InputDate and the script ran fine
with the new object.
i think its because of the default date the application set by default. Is there anyway i can execute the java script with an other value other than “document.getElementById? please suggest
Unfortunately I couldnt tried that option afterwards.
Meantime i am facing a new issue. I have another calender type where i need to capture only the month and year in the format Feb/2015 as an example. Screenshot as below.
I have tried the same java script which i tried to remove the read only attribute first and tried to set text as Feb/2015. But it failed at javascript execution itself. My code is as below.
executeJavaScript(“document.getElementById(‘productivityComplaintReportSubview:productivityComplaintReportFomId:monthCalendarIdInputDate’).removeAttribute(‘readonly’)”, null) FAILED.
Reason:
com.kms.katalon.core.exception.StepFailedException: Unable to execute JavaScript. (Root cause: org.openqa.selenium.WebDriverException: unknown error: Cannot read property ‘removeAttribute’ of null
(Session info: chrome=72.0.3626.119)
(Driver info: chromedriver=2.43.600210 (68dcf5eebde37173d4027fa8635e332711d2874a),platform=Windows NT 10.0.17134 x86_64) (WARNING: The server did not provide any stacktrace information)
The error indicates that document.getElementById() returns a null object. Are you certain that the Id is correct ? It would help if you can screenshot the HTML and highlight the element you want to select.
when i am executing WebUI.executeJavaScript(“document.getElementsByClass(‘leaveDatePicker datepic_icon form-control ng-pristine ng-valid hasDatepicker ng-touched’).removeAttribute(‘readonly’);”, null)
Caused by: org.openqa.selenium.WebDriverException: unknown error: document.getElementsByClassName(…).removeAttribute is not a function