0

I am using swift 4.2 so I am not sure if my code is outdated because many of the examples are not for the latest.

I have been trying many of the examples I have found here on stack but it seems they are outdated because of many references not valid working anymore.

I am trying to get the innerText of an element with a particular ID. Unfortunately I produce no results in successfully getting the value. Then I am trying to take result and put it in Firebase. If I use something like "test" instead of result it works fine, but I need result

Here is my code.

override func viewDidLoad() {
    super.viewDidLoad()

    ref = Database.database().reference()

    webView.evaluateJavaScript("document.getElementById('get_this_user').innerText") { (result, error) in
        self.ref?.child("users").child("usernames").setValue(["get_this_user": result])
    }
}
Cesar Bielich
  • 4,754
  • 9
  • 39
  • 81
  • any error from evaluateJavaScript? Is your webview done loading the content? – koropok Dec 13 '18 at 04:48
  • No error, Since I posted this I am learning that I am pretty sure that is the issue. The content is not loaded so now I am trying to figure out how to wait till the content (HTML) is loaded – Cesar Bielich Dec 13 '18 at 04:48
  • Depending on the content, you can use either WKNavigationDelegate's didFinish function or key-value observation to determine if the content has been loaded – koropok Dec 13 '18 at 04:55
  • Have some examples? – Cesar Bielich Dec 13 '18 at 04:55
  • check this out: https://stackoverflow.com/questions/30291534/wkwebview-didnt-finish-loading-when-didfinishnavigation-is-called-bug-in-wkw both the solutions that I've mentioned are inside. – koropok Dec 13 '18 at 04:56

0 Answers0