Can't inspect element in web browser - Android

Currently I am using Appium latest version, I am able to launch the browser. However, it doesn’t show any element. I think this is because my app url is https. In the inspector window, it said "Error getting source page: For security reasons DTD is prohibited in this XML document. To enable DTD processing set the DtdProcessing property on XmlReaderSettings to Parse and pass the settings into XmlReader.Create method. I am not sure how to solve this problem. Anyone has the same issue?

@fl41517
You didn’t provide any Appium logs or anything that really help, but I am gonna answer as much as I can.

XML DTD is disabled by default in all XML readers to prevent creating what is called an XML Bomb (Where you reference an already defined element in multiple levels and cause the XML reader to overflow the machine’s memory and crash it), Your website’s source is fetched correctly but, the xml tree creator has detected a DTD reference and hence the error.

This is not a bug in Appium and for security reasons this check should remain on. My advice to you is to refer to the website developers for help on changing the element that is causing the problem.

Here is the log after I direct to the page and hit refresh in Inspector Window. It looks like it did fetch the code, but it cant parse it.

info: [debug] Proxying command to 127.0.0.1:9515

info: [debug] Making http request with opts: {“url”:“http://127.0.0.1:9515/wd/hub/session/6d141a23ad172d9d21b2aae3074419cb/source",“method”:"GET”}
info: [debug] Proxied response received with status 200: “{"sessionId":"6d141a23ad172d9d21b2aae3074419cb","status":0,"value":"\u003C!DOCTYPE html>\u003C!-- Conditional stylesheets vs CSS hacks? Answer: Neither! - Paul Irish → \u003C!–[if IE 7 ]> \u003Chtml class=\"ie7\" lang=\"en\"> \u003C![endif]–>\u003C!–[if IE 8 ]> \u003Chtml class=\"ie8\" lang=\"en\"> \u003C![endif]–>\u003C!–[if (gte IE 9)|!(IE)]>\u003C!–>\u003Chtml xmlns=\"http://www.w3.org/1999/xhtml\\\” lang=\"en\" class=\"\">\u003C!–\u003C![endif]–>\u003Chead>\u003Cscript type=\"text/javascript\" async=\"\" src=\"https://nexus.ensighten.com/hp/lighthouse_dev/code/1960d668e6397cc09f17961e61f3c1ac.js?ruleId=384357\\\“>\u003C/script>\u003Cscript src=\"https://nexus.ensighten.com/hp/lighthouse_dev/serverComponent.php?r=2101.679441984743&ClientID=217&PageID=https%3A%2F%2Fnightly.lightaria.com%2F\\\”>\u003C/script>\n \u003Ctitle>HP Touchpoint Manager\u003C/title>\n \u003Cmeta charset=\"utf-8\" />\n \u003Cmeta http-equiv=\"cache-control\" content=\"no-cache\" />\n \u003Cmeta http-equiv=\"pragma\" content=\"no-cache\" />\n \u003Cmeta http-equiv=\"X-UA-Compatible\" content=\"IE=9\" />\n \u003Cmeta name=\"author\" content=\"Hewlett-Packard Development Company, L.P.\" />\n \u003Cmeta name=\"copyright\" content=\"© 2014 Hewlett-Packard Development Company, L.P.\" />\n \u003Cmeta name=\"description\" content=\"HP Touchpoint Manager\" />\n \u003Cmeta name=\"keywords\" content=\"HP Touchpoint Manager\" />\n \u003Cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n \u003Clink href=\"/assets/apple_touch_icon-0cdf7b1da8622516019a0abc65ed0c9b.png\" rel=\"icon\" sizes=\"192x192\" type=\"image/png\" />\n \u003Clink href=\"/assets/apple_touch_icon-0cdf7b1da8622516019a0abc65ed0c9b.png\" rel=\"apple-touch-icon\" type=\"image/png\" />\n \u003Clink href=\"/assets/apple_touch_icon-0cdf7b1da8622516019a0abc65ed0c9b.png\" rel=\"apple-touch-icon-precomposed\" type=\"image/png\" />\n \u003Cmeta name=\"web_section_id\" content=\"R11682\" />\n\n \u003Cscript>\n document.documentElement.className = document.documentElement.className.replace(\"no_js\", \"\");\n \u003C/script>\n\n \u003Clink rel=\"icon\" href=\"/assets/favicons/favicon-7b3b0db5e4b279f18bad711e4a520601.ico\" type=\"image/x-icon\" />\n\n \u003Cmeta content=\"authenticity_token\" name=\"csrf-param\" />\n\u003Cmeta content=\"dXP09yCVmS637OC+NpVVQ7BGQ17TnoZ9/Jx71ZBi9Uc=\" name=\"csrf-token\" />\n\n \u003Clink href=\"/assets/welcome-74fbf424ca877244b3b5b5f42291bad7.css\" media=\"all\" rel=\"stylesheet\" type=\"text/css\" />\n\n\n\n \u003C!-- IE Fix for HTML5 Tags → \n \u003C!–[if lt IE 9]>\n \u003Cscript src=\"http://html5shiv.googlecode.com/svn/trunk/html5.js\\\">\u003C/script>\n \u003C![endif]–>\n \u003C/head>\n\n \u003Cbody id=\"lighthouse-app\" data-namespace=\"null\" data-controller=\"sessions\" data-action=\"new\" data-default-locale=\"en\" data-locale=\"en\" data-user=\"null\" data-supported-languages=\"{"en":"English (United States)","fr":"Fran\\u00e7ais","ja":"\\u65e5\\u672c\\u8a9e"}\" class=\"breakpoint-1\">\n \u003Cdiv id=\"wrapper\">\n \u003Cheader>\n \u003Cdiv class=\"container\">\n \u003Cdiv class=\"row\">\n \u003Cdiv class=\"span12\">\n \u003Ch1>\n \u003Ca href=\"/\" id=\"lighthouse_logo\" title=\"HP Touchpoint Manager\">HP Touchpoint Manager\u003C/a>\n \u003C/h1>\n \u003Cdiv class=\"logo_divider\">\u003C/div>\n \u003Cnav id=\"menu\">\n \u003Cul class=\"right\">\n \u003Cli>\u003Cdiv class=\"menu_divider\">\u003C/div>\u003C/li>\n \u003Cli>\n \u003Ca href=\"#\" id=\"btn_change_language\">\n \u003Ci class=\"icon_language\">\u003C/i>\u003Cspan class=\"hidden-phone\">Change Language\u003C/span>\n \u003Cform id=\"form_language\" action=\"/settings/language\" method=\"post\">\n \u003Cselect class=\"visible-phone\" id=\"language\" name=\"language\">\u003Coption value=\"en\" selected=\"selected\">English (United States)\u003C/option>\n\u003Coption value=\"fr\">Français\u003C/option>\n\u003Coption value=\"ja\">日本語\u003C/option>\u003C/select>\n \u003C/form>\n \u003C/a>\n \u003C/li>\n \u003C/ul>\n \u003C/nav>\n \u003C/div>\n \u003C/div>\n \u003C/div>\n\u003C/header>\n\n \u003Cdiv id=\"lighthouse-wrapper\" data-controller-class=\"sessionscontroller\" data-controller-name=\"sessions\" data-action=\"new\" data-default-locale=\"en\" data-locale=\"en\">\n \u003Cdiv class=\"container\">\n \u003Cdiv id=\"welcome_page\">\n \u003Cdiv class=\"row\">\n \u003Cdiv class=\"span8\" id=\"banner\">\n \u003Cimg alt=\"IT Management made simple\" src=\"/assets/welcome/banner_en-00902cfc26a0bec2540d4399c2bb7b6f.jpg\" />\n \u003C/div>\n \u003Cdiv class=\"span4\" id=\"form_content\">\n \u003Cdiv class=\"box\">\n \u003Cdiv id=\"sign_in_area\" class=\"content\">\n \u003Cdiv class=\"form_header\">\n \u003Ch4>Sign In\u003C/h4>\n \u003C/div>\n\n \u003Cform accept-charset=\"UTF-8\" action=\"/users/sign_in\" class=\"display\" id=\"sign_in_form\" method=\"post\">\u003Cdiv style=\"margin:0;padding:0;display:inline\">\u003Cinput name=\"utf8\" type=\"hidden\" value=\"✓\" />\u003Cinput name=\"authenticity_token\" type=\"hidden\" value=\"dXP09yCVmS637OC+NpVVQ7BGQ17TnoZ9/Jx71ZBi9Uc=\" />\u003C/div>\n\n\n\n \u003Cp>\n \u003Clabel for=\"sign_in_user_email\">E-mail\u003C/label>\n \u003Cinput class=\"inline\" id=\"sign_in_user_email\" maxlength=\"60\" name=\"user[email]\" size=\"60\" tabindex=\"1\" type=\"text\" value=\"\" />\n \u003C/p>\n\n \u003Cp>\n \u003Clabel for=\"sign_in_user_password\">Password\u003C/label>\n \u003Cinput class=\"inline\" data=\"user_password\" id=\"sign_in_user_password\" maxlength=\"20\" name=\"user[password]\" size=\"20\" tabindex=\"2\" type=\"password\" />\n \u003C/p>\n\n \n \u003Cinput id=\"user_settings_language\" name=\"user_settings[language]\" type=\"hidden\" value=\"en\" />\n\n \u003Cp class=\"button_area\">\n \u003Cbutton class=\"inline primary\" id=\"sign_in_submit\" name=\"button\" tabindex=\"3\" type=\"submit\">Sign In\u003C/button>\n\n \u003Ca href=\"/users/password/new\" id=\"password_recover\">Can’t access your account?\u003C/a>\n\n \u003Cbutton type=\"button\" id=\"sign_up_button\" class=\"critical inline\">Sign Up\u003C/button>\n \u003C/p>\n\n\u003C/form>\u003C/div>\n\n\u003Cdiv id=\"sign_up_area\" class=\"content\">\n \u003Cform accept-charset=\"UTF-8\" action=\"/users\" class=\"display\" id=\"sign_up_form\" method=\"post\">\u003Cdiv style=\"margin:0;padding:0;display:inline\">\u003Cinput name=\"utf8\" type=\"hidden\" value=\"✓\" />\u003Cinput name=\"authenticity_token\" type=\"hidden\" value=\"dXP09yCVmS637OC+NpVVQ7BGQ17TnoZ9/Jx71ZBi9Uc=\" />\u003C/div>\n\n\n\n \u003Cp>\n \u003Clabel for=\"user_first_name\">First Name\u003C/label>\n \u003Cinput class=\"inline\" id=\"user_first_name\" maxlength=\"30\" name=\"user[first_name]\" size=\"30\" tabindex=\"4\" type=\"text\" />\n \u003C/p>\n\n \u003Cp>\n \u003Clabel for=\"user_last_name\">Last Name\u003C/label>\n \u003Cinput class=\"inline\" id=\"user_last_name\" maxlength=\"30\" name=\"user[last_name]\" size=\"30\" tabindex=\"5\" type=\"text\" />\n \u003C/p>\n\n \u003Cp>\n \u003Clabel for=\"user_email\">E-mail\u003C/label>\n \u003Cinput class=\"inline\" id=\"user_email\" maxlength=\"60\" name=\"user[email]\" size=\"60\" tabindex=\"7\" type=\"text\" value=\"\" />\n \u003C/p>\n\n \u003Cinput id=\"company_time_zone\" name=\"user[company_time_zone]\" type=\"hidden\" />\n\n \u003Cp>\n \u003Clabel for=\"sign_up_user_password\">Password\u003C/label>\n \u003Cinput class=\"inline\" id=\"sign_up_user_password\" maxlength=\"20\" name=\"user[password]\" size=\"20\" tabindex=\"9\" type=\"password\" />\n \u003C/p>\n\n \u003Cp>\n \u003Clabel for=\"user_password_confirmation\">Confirm Password\u003C/label>\n \u003Cinput class=\"inline\" id=\"user_password_confirmation\" maxlength=\"20\" name=\"user[password_confirmation]\" size=\"20\" tabindex=\"10\" type=\"password\" />\n\n \u003C/p>\n\n \u003Cp class=\"tc_and_ops_message\">\n\n \u003Cinput name=\"user[terms_of_use]\" type=\"hidden\" value=\"0\" />\u003Cinput id=\"user_terms_of_use\" name=\"user[terms_of_use]\" tabindex=\"11\" type=\"checkbox\" value=\"1\" />\n \u003Clabel for=\"user_t
info: e[37m<-- GET /wd/hub/session/6d141a23ad172d9d21b2aae3074419cb/source e[39me[32m200e[39me[90m 1765.692 ms - 14875e[39m e[90me[39m
info: e[37m–>e[39m e[37mGETe[39m e[37m/wd/hub/session/6d141a23ad172d9d21b2aae3074419cb/screenshote[39m e[90m{}e[39m
info: [debug] Proxying command to 127.0.0.1:9515

Can you please use Chrome driver’s remote debugging feature and make sure that you can inspect elements with it.

1 Like

Thanks! i can get the elements now. How should I generate code for autotesting? Since I can’t use Inspector window to record action anymore.

You will have to do that manually I guess :frowning:

Do you know where I can find some sample java test for browser? their documentation is not clear enough.

This should help you get thing started https://github.com/appium/sample-code/blob/master/sample-code/examples/java/junit/src/test/java/com/saucelabs/appium/AndroidWebViewTest.java

Everything after that is like working with Selenium webdriver normally :slight_smile:

This is for webview instead of Browser testing. Do you know one that is for browser testing?

Sorry my bad, All the Java tests can be found here: https://github.com/appium/sample-code/tree/master/sample-code/examples/java/junit

There is a test for Safari browser there :smile:

It seems like the latest Appium java2.0.0 jar has some bug. The AppiumDriver can’t instantiate. it gives error by the following line:driver = new AppiumDriver(new URL(“http://127.0.0.1:4723/wd/hub”), capabilities);
But it’s good after I changed to 1.7.0 jar

It’s not a bug, it’s a change in design. Please use AndroidDriver or iOSDriver respectively depending on your environment.

As mentioned here in the Structure section:

There is an abstract AppiumDriver class which inherits from the Selenium Java Client. The AppiumDriver class contains all methods shared by iOS and Android. IOSDriver and AndroidDriver both extend AppiumDriver and provide more methods, and specific implementations for some methods.

here is my test.java. However, when I hit Run as JUnit test. It said : "Launching BrowserTest has encountered a problem.
An internal error occurred during: “Launching BrowserTest”.
java.lang.NullPointerException

import io.appium.java_client.AppiumDriver;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.io.File;
import java.net.URL;
import java.util.Set;

public class BrowserTest {
private AppiumDriver driver;

@Before
public void setUp() throws Exception {
    // set up appium
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.BROWSER_NAME, "chrome");
    capabilities.setCapability("automationName","Selendroid");
    capabilities.setCapability("platformName", "Android");
    driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
@After
public void tearDown() throws Exception {
    driver.quit();
}

@Test
public void webView() throws InterruptedException {
    driver.get("https://nightly.lightaria.com");
}

}

Stack trace of the exception please…

the console didnt show anything.it stopped as soon as I press run

Then it’s a problem with your IDE not able to find some library reference or something, please make sure that the following is added to your class path: Appium Java client, Selenium, Junit.

Also you can try with a different IDE and see the results.