Hi I trying to open webpage and auto to click some button
but it will not working in my iPhone , please tell me how can i fix that
let url = "https://shopee.tw/shopee-coins";
let wv = new WebView()
await wv.loadURL(url)
//get elements with mobile mode
let js =`document.getElementsByClassName('.mobilemall-coinsrewardpage_327hN9').click();`
wv.evaluateJavaScript(js)
await wv.present()
I think it should load the webpage then use js variable to click the button
but in loadURL() will not show it
so I change to after loadURL() should present()
but i don’t know is correct or not …
Your in-page JS is trying to click on an array of page elements, which doesn’t work, because the click() method can only act on a single element. You’ll need to use document.getElementsByClassName(...)[0] to isolate the element you want to click.
I suggest awaiting wv.evaluateJavaScript(js) so that it has already finished running by the time you see it.
So like this:
let url = "https://shopee.tw/shopee-coins";
let wv = new WebView()
await wv.loadURL(url)
//get elements with mobile mode
let js =`document.getElementsByClassName('.mobilemall-coinsrewardpage_327hN9')[0].click();`
await wv.evaluateJavaScript(js)
await wv.present()
It shouldn’t though. Even though it only grabs one element, it’s still an array–with one item in it. That’s how the getElementsByClassName() method works. It’s not like getElementById which returns a lone element.