3

Hey I'm trying to figure out how to click this simple little button but I'm failing.

This is the correct code implementation but wrong path in javascript. I need to click on the a<

Or if I can just call the function connected to the button

enter image description here

enter image description here

I've also tried to click on the td< but nothings happens because the button is actually the a<

Code:

 // no errors print but nothing happens
self.webView.evaluateJavaScript("document.getElementById('participant-page-results-more').click();"){ (value, error) in

        if error != nil {
            print(error!)
        }

    }

UPDATED Answer still nothing but I think were close, @Michael Hulet:

       self.webView.evaluateJavaScript("document.querySelector('#participant-page-results-more').getElementsByTagName('a')[0].click();"){ (value, error) in
        if error != nil {
            print(error!)
        } else {
        }
    } 

    // Or

        self.MainWebView.evaluateJavaScript("document.querySelector('#participant-page-results-more a').click();"){ (value, error) in
        if error != nil {
            print(error!)
        } else {
        }
    }

But interestingly enough when I use the .innerText in stead of the .click a get back the Show more matches label.

UPDATE 2:

trying to load the function directly does nothing either

  self.MainWebView.evaluateJavaScript("window.loadMoreGames();"){ (value, error) in
        if error != nil {
            print(error!)
        }
    }

    // Or

    self.MainWebView.evaluateJavaScript("window[loadMoreGames]"){ (value, error) in
        if error != nil {
            print(error!)
        }
    }

    // Or

    self.MainWebView.evaluateJavaScript("loadMoreGames();"){ (value, error) in
        if error != nil {
            print(error!)
        }
    }

1 Answer 1

3

In order to trigger the function, you need to click on the <a> tag (the HTML tag that listens for clicks), but the id you're looking up is on the <table> tag. Note that the key change here is a different selector/selection method, but try this:

self.webView.evaluateJavaScript("document.querySelector('#participant-page-results-more a').click();"){ (value, error) in

    if let err = error {
        print(err)
    }

}
Sign up to request clarification or add additional context in comments.

5 Comments

What happens if you just call loadMoreGames() directly instead of going through the whole song and dance of getting the <a> tag?
I can tell you. If I know how to write out the code for it. Think you can help me out?
Instead of passing all that you're doing rn to evaluateJavaScript, try just passing loadMoreGames(); (or window.loadMoreGames(); if you get anything about loadMoreGames being undefined)
And it works just fine if you manually click on the button yourself on your device?
yea that's the bad part everything seems perfect

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.