我正在尝试用Appium
单击一些移动元素(JavascriptExecutor
)。
它抛出org.openqa.selenium.WebDriverException
:
(见下文)
我的代码很简单。
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);
上面的element
可以。
所以我的问题是:
我可以将JavascriptExecutor
与Appium
移动元素一起使用吗?如果可以,我应该使用JavascriptExecutor
进行哪些更改?
unknown error (An unknown server-side error occurred. status='false'. Failed to complete internal method: 'hybridRunJavascript args: [, 0, result = null;resultType = null;resultMessage = null;function getPathToWithSuffix(element,suffix) {if (element.tagName.toUpperCase() == "HTML".toUpperCase())return '//html'+suffix;if (element===document.body)return '//html/body[1]'+suffix;var ix= 0;var siblings= element.parentNode.childNodes;for (var i= 0; i<siblings.length; i++) {var sibling= siblings[i];if (sibling===element)return getPathToWithSuffix(element.parentNode,'/'+element.tagName.toLowerCase()+'['+(ix+1)+']'+suffix);if (sibling.nodeType===1 && sibling.tagName===element.tagName)ix++;}}function runScriptResultWrapper(element){if((typeof element === undefined) || element == null){result = null;resultMessage = null;return;}else if (typeof element === 'string' || element instanceof String){result = element;resultType = "string";resultMessage = null;return;}else if (typeof element === 'number' || element instanceof Number){if(element % 1 === 0){resultType = "int"}else{resultType = "float";}result = element;resultMessage = null;return;}else if (typeof element === 'boolean' || element instanceof Boolean){resultType = "boolean";result = element;resultMessage = null;return;}var paths = [];if(element.constructor === Array || element.length > 0){var elements = element;for (i = 0; i < elements.length; i++) {var elementPath = getPathToWithSuffix(elements[i],"");paths[i] = elementPath;}resultMessage = null;}else if(!element.parentNode){resultType = "object";result = element;resultMessage = null;return;}else{resultMessage = null;paths[0] = getPathToWithSuffix(element,"");}resultType = null;result = {value: paths};};var userFunc = function() {var arguments = new Array();arguments[0]=document.evaluate("(//*[@resource-id='text' or @id='text'])[1]", document, null, XPathResult.ANY_TYPE, null).iterateNext();;arguments[0].click();;};result = null;var temp_result = userFunc();if(result == null) {result = temp_result;} runScriptResultWrapper(result);]', details: Failed to run javascript '': null) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
答案 0 :(得分:1)
在Appium中,您只能将executeScript() method用于运行Mobile Commands
喜欢:
Map<String, Object> params = new HashMap<>();
params.put("direction", "down");
params.put("element", ((RemoteWebElement) element).getId());
driver.executeScript("mobile: swipe", params);
所以我的期望是您应该改用element.click()
method。
如果您对“常规”点击有疑问-您可以考虑使用SeeTest - Appium Extension Click command,它可以执行多次点击并使用OCR定位元素