以下是我的代码,该应用程序在运行时启动,但无法选择该按钮,会出现如下错误:
是因为我使用的是RemoteWebDriver而不是AndroidDriver吗?
Appium错误日志:
> info: [debug] Responding to client with error: {"status":7,"value":{"message":"An element could not be located on the page using the given search parameters.","origValue":"Element was not found."},"sessionId":"633dd3fe-7233-eb66-8903-c63b69246cf0"}
> info: <-- POST /wd/hub/session/633dd3fe-7233-eb66-8903-c63b69246cf0/element 500 30181.879 ms - 201
info: - &gt; DELETE / wd / hub / session / 633dd3fe-7233-eb66-8903-c63b69246cf0 {} 信息:关闭appium会话
Eclipse错误日志:
Test Started
FAILED: test
org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 30.19 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:59:20'
System info: host: 'NCA1026471', ip: '192.168.56.1', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_66'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities [{app=C:\Appium\selendroid-test-app-0.17.0.apk, appPackage=io.selendroid.testapp, rotatable=true, networkConnectionEnabled=true, warnings={}, handlesAlerts=true, deviceName=Lokesh Gangaiah, version=0.17.0, platform=ANDROID, appActivity=io.selendroid.testapp.HomeScreenActivity, desired= {app=C:\Appium\selendroid-test-app-0.17.0.apk, appPackage=io.selendroid.testapp, appActivity=io.selendroid.testapp.HomeScreenActivity, platformVersion=5.0, browserName=, platformName=Android, deviceName=Lokesh Gangaiah, device=Android}, acceptSslCerts=true, platformVersion=21, automationName=selendroid, browserName=selendroid, takesScreenshot=true, javascriptEnabled=true, platformName=android, device=Android}]
Session ID: 633dd3fe-7233-eb66-8903-c63b69246cf0
*** Element info: {Using=id, value=io.selendroid.testapp:id/buttonStartWebview}
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
java代码:
import java.io.File;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.mobile.*;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class testP1 {
public static RemoteWebDriver driver;
//public static AndroidDriver<MobileElement> driver;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
File appDir = new File ("C:\\Appium\\");
//File app = new File (appDir,"CarsGuide com au_v1.0.8.1_apkpure.com.apk");
File app = new File (appDir,"selendroid-test-app-0.17.0.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("browserName", "");
//capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("deviceName", "Lokesh Gangaiah");
capabilities.setCapability("platformVersion", "5.0");
capabilities.setCapability("device", "Android");
capabilities.setCapability("app",app.getAbsolutePath());
capabilities.setCapability("appPackage", "io.selendroid.testapp");
capabilities.setCapability("appActivity", "io.selendroid.testapp.HomeScreenActivity");
//capabilities.setCapability("appPackage", "au.com.carsguide");
//capabilities.setCapability("appActivity", "au.com.carsguide.activity.HomeActivity");
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void test() throws InterruptedException {
System.out.println("Test Started");
WebElement ButtonElement = driver.findElementById("io.selendroid.testapp:id/buttonStartWebview");
ButtonElement.click();
Thread.sleep(3000L);
System.out.println("Test has been completed");
//System.out.println("Hello2");
// driver.findElementByName("Search Cars for Sale").click();
//By.id("au.com.carsguide:id/search_btn").findElement(driver).click();
Thread.sleep(1000L);
}
@AfterClass
public void tearDown()
{
driver.quit();
}
}
添加wait之后的新错误:来自eclipse控制台的日志
Test Started
FAILED: test
org.openqa.selenium.TimeoutException: Timed out after 20 seconds waiting for visibility of element located by By.id: io.selendroid.testapp:id/buttonStartWebview
构建信息:版本:&#39; 2.48.2&#39;,修订版:&#39; 41bccdd&#39;,时间:&#39; 2015-10-09 19:59:20&#39; 系统信息:主持人:&#39; NCA1026471&#39;,ip:&#39; 192.168.56.1&#39;,os.name:&#39; Windows 7&#39;,os.arch:&#39; amd64&#39;,os.version:&#39; 6.1&#39;,java.version:&#39; 1.8.0_66&#39; 驱动程序信息:org.openqa.selenium.remote.RemoteWebDriver 功能[{app = C:\ Appium \ selendroid-test-app-0.17.0.apk,appPackage = io.selendroid.testapp,rotate = true,networkConnectionEnabled = true,warnings = {},handlesAlerts = true,deviceName = Lokesh Gangaiah,版本= 0.17.0,platform = ANDROID,appActivity = io.selendroid.testapp.HomeScreenActivity,desired = {app = C:\ Appium \ selendroid-test-app-0.17.0.apk,appPackage = io.selendroid。 testapp,appActivity = io.selendroid.testapp.HomeScreenActivity,platformVersion = 5.0,browserName =,platformName = Android,deviceName = Lokesh Gangaiah,device = Android},acceptSslCerts = true,platformVersion = 21,automationName = selendroid,browserName = selendroid,takesScreenshot = true,javascriptEnabled = true,platformName = android,device = Android}] 会议ID:990a6104-0d06-f75a-876c-531a23388b7c
FAILED CONFIGURATION: @BeforeClass setUpBeforeClass
java.lang.Error: Unresolved compilation problems:
The return types are incompatible for the inherited methods FindsByAccessibilityId<WebElement>.findElementsByAccessibilityId(String), AppiumDriver<RequiredElementType>.findElementsByAccessibilityId(String)
The return types are incompatible for the inherited methods FindsByCssSelector.findElementsByCssSelector(String), AppiumDriver<RequiredElementType>.findElementsByCssSelector(String)
答案 0 :(得分:0)
在点击之前添加一些等待命令:
@Test
public void test() throws InterruptedException {
System.out.println("Test Started");
//wait for the button to show up before clicking
waitForElementPresent();
WebElement ButtonElement = driver.findElementByName("buttonStartWebviewCD");
ButtonElement.click();
}
public void waitForElementPresent() {
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("buttonStartWebviewCD")));
}