Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode UI Test - how to tap() link in WKWebView?

I'm trying to tap a link in a WKWebView using UI Test. The link is defined like so:

<a data-toggle="tab" href="#haloLogin">
<img src=/Images/Halo_small.png">
</a>

I'm able to locate the link like this:

let haloLink = app.links.elementBoundByIndex(1) 

(There's another link at index 0)

This is what I get when I print out haloLink.debugDescription:

haloLink: Attributes: Link 0x1257094e0: traits: 146029019138, {{143.0, -392.0}, {32.0, 32.0}}

Element subtree:
→Link 0x1257094e0: traits: 146029019138, {{143.0, -392.0}, {32.0, 32.0}}
Image 0x125709cf0: traits: 146029019142, {{143.0, -392.0}, {32.0, 32.0}}

I've tried using

app.links["#haloLogin"] 

without success.

My problem is that I'm not getting

haloLink.tap() 

to work.

Any suggestions are welcome!

like image 684
MickeDG Avatar asked Dec 22 '25 13:12

MickeDG


2 Answers

If the element in wkwebviw like this.

<a href="#">your link text</a>

Then the test code is below

app.links["your link text"].tap()

Look more in the article. UI Testing Cheat Sheet and Examples

like image 110
iamhite Avatar answered Dec 24 '25 05:12

iamhite


Access the link via the contained image. In your question your image's filename is Halo_small.png, so you can tap() it with:

let app = XCUIApplication()
app.images["Halo_small.png"].tap()
like image 22
Joe Masilotti Avatar answered Dec 24 '25 03:12

Joe Masilotti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!