This time I try to use espresso to test my app. I use webview to open the url and check below html code I face the question that I can`t access the element in iframe.
<html>
<head></head>
<body>
<iframe id="mainFrame" src="Address/Default.aspx" scrolling="no"
style="border: 0px; width: 100%; height: 432px; position: absolute;">
<html>
<head></head>
<body>
<button onclick = "one function">
</body>
</html>
</iframe>
</body>
</html>
I copy the XPTH that is /html/body/button and code
onWebView().withElement(findElement(Locator.XPATH, "/html/body/button")).perform(webClick());
However, I get Atom evaluation returned null! and I can not get element. Can espresso get element inside iframe? I can get element not in iframe.
As the button is inside an
iframe, thus we need to use.inWindow(selectFrameByIdOrName("mainFrame"))
onWebView()
.inWindow(selectFrameByIdOrName("mainFrame"))
.withElement(findElement(Locator.XPATH, "/html/body/button")).perform(webClick());
Hope that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With