我试图打开selenium.org并单击项目选项卡,但对象无法识别(甚至使用uiautomator直到页面被缩放).Hence也尝试缩放以便对象可识别。但缩放功能不起作用。还有其他方法可以找到元素。
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import java.io.File;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.FindBy;
import org.testng.AssertJUnit;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class OpenBrowser {
private AppiumDriver <WebElement> AndDriver;
@BeforeMethod
public void setUp() throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("browserName", "Chrome");
capabilities.setCapability("device", "Android");
capabilities.setCapability("deviceName", "TA9330416L");
capabilities.setCapability("platformVersion", "5.1");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "com.android.chrome");
capabilities.setCapability("appActivity", "org.chromium.chrome.browser.document.ChromeLauncherActivity");
AndDriver = new AndroidDriver <WebElement>(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
}
@AfterMethod
public void tearDown() throws Exception {
AndDriver.quit();//Always quit your driver
}
@Test
public void launchWebsite()throws InterruptedException {
AndDriver.get("http://www.seleniumhq.org");
Thread.sleep(3000);
AndDriver.pinch(323,323);
AndDriver.findElement(By.name("Projects")).click();
}
}
/*
FAILED: launchWebsite
org.openqa.selenium.WebDriverException: unknown error: operation is unsupported on Android
(Session info: chrome=46.0.2490.76)
(Driver info: chromedriver=2.18.343845 (73dd713ba7fbfb73cbb514e62641d8c96a94682a),platform=Windows NT 6.3 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 18 milliseconds
Build info: version: '2.45.0', revision: '32a636c', time: '2015-03-05 22:01:35'
System info: host: 'USHYDPTHAKURI1', ip: '10.14.225.155', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_40'
Driver info: io.appium.java_client.android.AndroidDriver
*/
答案 0 :(得分:1)
使用您提供的功能,您将获得Chromium作为应用程序,而不是浏览器。所以,没有方法可以获得&#39;对于这个应用程序。