请解决我的问题
您可以在appium native app上编写您在网站上提到的相同代码,但它会出错 主要错误是: -
Exception in thread "main" org.openqa.selenium.WebDriverException: Returned value cannot be converted to WebElement: {ELEMENT=1}
请检查附件以获得更多说明
我的代码: -
private static AndroidDriver driver;
public static void main(String[] args) throws MalformedURLException, InterruptedException {
// TODO Auto-generated method stub
// Create object of DesiredCapabilities class
DesiredCapabilities capabilities = new DesiredCapabilities();
// Optional
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
// Specify the device name (any name)
capabilities.setCapability("deviceName", "My New Phone");
// Platform version
capabilities.setCapability("platformVersion", "5.1");
// platform name
capabilities.setCapability("platformName", "Android");
// specify the application package that we copied from appium
capabilities.setCapability("appPackage", "io.selendroid.testapp");
// specify the application activity that we copied from appium
capabilities.setCapability("appActivity", ".HomeScreenActivity");
// Start android driver I used 4727 port by default it will be 4723
driver = new AndroidDriver(new URL("http://127.0.0.1:4727/wd/hub"), capabilities);
// Specify the implicit wait of 5 second
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
// Enter the text in textbox
driver.findElement(By.xpath("//android.widget.EditText[@content-desc='my_text_fieldCD']")).sendKeys("Mukesh Selenium Appium");
// click on registration button
driver.findElement(By.id("io.selendroid.testapp:id/startUserRegistration")).click();
// Wait for 10 second
Thread.sleep(5000L);
}}
我的错误是: -
Sep 14, 2017 3:36:41 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
Exception in thread "main" org.openqa.selenium.WebDriverException: Returned value cannot be converted to WebElement: {ELEMENT=1}
Build info: version: 'unknown', revision: '5234b32', time: '2017-03-10 09:00:17 -0800'
System info: host: 'DESKTOP-92C398N', ip: '192.168.1.14', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_121'
Driver info: driver.version: AndroidDriver
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:378)
at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:62)
at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:476)
at io.appium.java_client.DefaultGenericMobileDriver.findElementByXPath(DefaultGenericMobileDriver.java:140)
at io.appium.java_client.AppiumDriver.findElementByXPath(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.findElementByXPath(AndroidDriver.java:1)
at org.openqa.selenium.By$ByXPath.findElement(By.java:361)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:363)
at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:58)
at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1)
at a1.Selendroid.main(Selendroid.java:34)
Caused by: java.lang.ClassCastException: java.util.HashMap cannot be cast to org.openqa.selenium.WebElement
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:376)
... 13 more
此致 Inderpreet kaur
答案 0 :(得分:1)
我是同样的问题
然后使用以下版本 鸦片:1.6.5
Selenium:selenium-java-3.3.1
Appium Java客户端:java-client-5.0.3
我将Appium客户端降级为:
Appium Java客户端:java-client-5.0.0-BETA6 问题解决了。