I want to use jQuery selector to get objects from html instead of using xpath. I’ve found some scripts in web, but when I use them, I am getting an error.
This is my JavaScript Executor:
public class Java {
@Keyword
def executeJavaScript(String javascript) {
((JavascriptExecutor) DriverFactory.getWebDriver()).executeScript(javascript)
}
}
And this is the test case:
String myJsScript = "jQuery('div.sc-bdVaJa sc-bwzfXH ldFBFf').text()"
def k = CustomKeywords.'apilayer.Java.executeJavaScript'(myJsScript)
println k
I’m getting error like this:
Reason:
groovy.lang.MissingPropertyException: No such property: CustomKeywords for class: custom.Script1559547421027
Test Cases/sda FAILED.
Reason:
groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.annotation.Keyword.apilayer.Java.exeJS() is applicable for argument types: (java.lang.String) values: [jQuery('div.sc-bdVaJa sc-bwzfXH ldFBFf').text()]
Test Cases/sda FAILED.
Reason:
groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.annotation.Keyword.apilayer.Java.exeJS() is applicable for argument types: (java.lang.String) values: [jQuery('div.sc-bdVaJa sc-bwzfXH ldFBFf').text()]
Suggestion for point 2: JavaScript is not ready yet.
Suggestion for point 1: jQuery is not loaded and ready yet.
Be sure that jQuery is loaded and ready. If your page uses jQuery then it is highly likely that jQuery will become very busy the moment it is ready. JavaScript is single-threaded. jQuery uses JavaScript. If you’re trying to use JavaScript/jQuery the moment jQuery is ready, you might create a race condition.
So, be patient. Slow your test down and wait for things to be ready.