简体   繁体   中英

Appium: the test is failing to automate a Web-based App

I'm trying to locate a WebElement on google.com page using Appium and AndriodDriver. Selenium throws an Exception every time I'm trying to run the code bellow. Client:

@Test
public void mobWebAppTest() throws Exception{
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("automationName", "Appium");
    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("platformVersion", "4.3");
    capabilities.setCapability("deviceName", "4df12fbe651cafd3");
    capabilities.setCapability("appPackage", "com.android.browser");
    capabilities.setCapability("appActivity", "BrowserActivity");
    capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");
    AndroidDriver<WebElement> driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    driver.get("https://www.google.com/");
    driver.findElement(By.xpath("//input[@name='q']")); // the error is thrown here
    driver.quit();  
}

Exception Logs:

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.31 seconds
For documentation on this error, please visit: 
http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.53.1', revision: 
'a36b8b1cd5757287168e54b817830adce9b0158d', time: '2016-06-30 19:26:09'
System info: host: '*******', ip: '*******', os.name: 'Mac OS X', os.arch: 
'x86_64', os.version: '10.10.5', java.version: '1.8.0_11'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{appPackage=com.android.browser, deviceScreenSize=720x1280, 
networkConnectionEnabled=true, warnings={}, databaseEnabled=false, 
deviceName=4df12fbe651cafd3, platform=LINUX, deviceUDID=4df12fbe651cafd3, 
appActivity=BrowserActivity, desired={appPackage=com.android.browser, 
appActivity=BrowserActivity, platformVersion=4.3, automationName=Appium, 
browserName=Android, platformName=Android, deviceName=4df12fbe651cafd3}, 
platformVersion=4.3, webStorageEnabled=false, locationContextEnabled=false, 
automationName=Appium, takesScreenshot=true, browserName=Android, 
javascriptEnabled=true, deviceModel=GT-I9300, platformName=Android, 
deviceManufacturer=samsung}]
Session ID: c68c1f7d-0e6e-481a-a335-23ede1de7de9
*** Element info: {Using=xpath, value=//input[@name='q']}
at ...

Also, when I'm trying to get a source code of the page, I'm getting back xml (as in ui automator) of the entire screen, not HTML of the google page. Could it be the reason for the exception?

THank you.

You need to switch to the web context first for DOM-level access:

driver.context("WEBVIEW_1");

You can get all available contexts with driver.getContextHandles() .

To automate the "Browser" app with Appium, you need to use desired capability "browserName": "Browser" instead of setting the appPackage & appActivity.

https://appium.io/slate/en/master/?java#appium-server-capabilities

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM