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

10,311

There is getPageSource() method:

driver.getPageSource();

Update

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

element.getAttribute('outerHTML')
Share:
10,311
pr4bh4sh
Author by

pr4bh4sh

Updated on June 04, 2022

Comments

  • pr4bh4sh
    pr4bh4sh about 2 years

    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);
    
  • pr4bh4sh
    pr4bh4sh about 9 years
    I don't want page source of entire page, I just want the page source of a specific element. Something like <h1 name="title">Title</h1>
  • Kirill
    Kirill about 9 years
    @pr4bh4sh, element.getAttribute('innerHTML')?
  • Kirill
    Kirill about 9 years
    Probably you need this: element.getAttribute('innerHTML')
  • kiedysktos
    kiedysktos about 8 years
    for iOS it doesn't work. "UIAElements don't have the attribute 'outerHTML'" - that's what Appium says
  • Kirill
    Kirill about 8 years
    @kiedysktos, try to change context from native to web.
  • Tomáš Hübelbauer
    Tomáš Hübelbauer about 2 years
    For CodeceptJS: await I.grabSource()