Elements in webview are not found in webview context (ios)

I’ve got a webview in this hierarchy:

//UIAApplication[1]/UIAWindow[1]/UIAScrollView[1]/UIAWebView

It contains 2 UIATextField’s and one UIATextField[1]

When I look for the elements while still in the native context, they are all found. In addition, I can click the button object while in the native context (strange)…

But when I switch to the WEBVIEW_1 context, none of the elements can be seen. Any ideas why?

BTW, while in native context I can see the Email element using this locator:
“//UIAScrollView/UIAWebView/UIATextField[@value=‘Email’]”

But while in WEBVIEW_1 context the element cannot be found using that locator, nor these:
“//UIAApplication[1]/UIAWindow[1]/UIAScrollView[1]/UIAWebView[1]/UIATextField[1]”
“//UIAWebView/UIATextField[1]”
“//UIATextField[1]”

QUESTION: While in a webview context, do we need to use a locator strategy other than the above?

Yes. You need to access the element as shown below

findElement(By.xpath("//input[@name=‘firstName’]")).

You have to use the page source to find the name of the element. Calling driver.getPageSource() will give the source code. Hope this help.

2 Likes

@Jeffrey_Blaze
You can use Chrome built-in feature (Remote debugging) to inspect for elements in webviews instead of getting the html source.

Use this link.

2 Likes

If we can access and manipulate UI elements without switching context, what’s the point of switching context?

You can’t access nor manipulate UI elements without switching contexts, I was just giving Jeffrey a simpler solution to inspect for elements instead of getting the whole HTML source.

Steve, It never worked for me without switching context so I am wondering how you could able to do that

Yeah, I’m quite stumped and have yet to hear back on my post.

1 Like

I was wondering if anyone made progress on this. I’m using the IOSDriver, and after switching to the webview, I can find elements that exist by using linkText.

I can’t find UIAButtons by using findElementsByName(). However, if I use an appium inspector, I am able to locate the UIAButtons by switching the context to webview, and then searching by the UIAButton’s name.

(I can switch context and locate a UIAButton by name using Appium Inspector, but not while running a test. It does work for finding elements by link text though.)

1 Like

@Hassan_Radi i checked the link and i found that its given only for ANdroid…
How to inspect WEBVIEW elements for IOS hybrid app.

I tried switching context to WEBVIEW and dumped the pageSource and started picking elements from the source file. But for some objects i was not able to figure out the elements manually.

Is there any way to inspect elements in iOS hyrbid App;s webview
Thanks

@Mobile_Test_Test
Check this out :smile:

Did you find a solution to this issue?

Any Solution for this? I am stuck here no clue what i can do

Please refer it…!

Thanks for reply. as you said the issue is developers has not enabled the visibility of the elements.