Search code examples
seleniumautomationappium

How to get page-source of an element in mobile native app by selenium script?


I'm using Appium for automation of mobile application and I want is just the pagesource of an element of a native app. I have googled a lot and found that its possible for webpages but did not get any solution for mobile's native app. like below examples.

elem.getAttribute("innerHTML");

OR

WebElement element = driver.findElement(By.id("foo"));
String contents = (String)((JavascriptExecutor)driver).executeScript("return arguments[0].innerHTML;", element);

Solution

  • There is getPageSource() method:

    driver.getPageSource();
    

    Update

    To get source code of specific element (including element's tag):

    element.getAttribute('outerHTML')