Doubt regarding javascript in webview

hi all, so I was trying to make a flower identification app using a service by bing and Java Script, so there is an option in this website that we can search images by URL of the image. as an example, I am using this image and i am using this code
document.getElementsByTagName('span')[12].textContent;
to get the name of the flower

when I try this code in the console of the website it works well

but when I try it in my app it returns null

My blockly code

URL used in my blockly code :https://www.bing.com/visualsearch/Microsoft/FlowerIdentification?&imgurl=https://i.ibb.co/PDshQYf/391126cd-977a-43c7-9937-4f139623cd58.jpg

JavaScript code used in my blockly code : - document.getElementsByTagName('span')[12].textContent;

can someone guide me on where I am going wrong

and I am making this project for learning purpose only

I am confused should I do it like this or use web view string

You have call your code in a function with return statement.

1 Like

If possible could you show some example how to do that

@HeyAveHey like this ?

function FlowerName() {
 return document.getElementsByTagName('span')[12].textContent;
}
1 Like

Yes something like that should work. Try to paste your code in evaluate js block.

In my project I have my own created html so i just write in js evaluate (for example) FlowerName(); as i could add the function to javascript code in html file in other words i get my return value just by calling the function name.

1 Like

If it doesn’t work try to:

function FlowerName() {
 return document.getElementsByTagName('span')[12].textContent;
};
FlowerName()

Im not fluent in javascript (i just used basics of js for my project) and i don’t know if u can call document.getelement in function without argument or variable.

If it doesn’t work you can try different setup like:

var x = document.getElementsByTagName('span')[12].textContent;

function FlowerName(x) {
 return x;
};
FlowerName()

or 

function FlowerName() {
 return x;
};
FlowerName()
1 Like

Hey i tried it , its returning a value but not the one i got in the console of the website

here is the aia file
flower_image_classifier (1).aia (69.2 KB)

its returning © 2021 Microsoft in the app and in the console of the website it returns the flower name

I tried it as well in firefox. Your definied element in my webviewer is not a flower name. Your element definition must be unprecise. Remember that every webviewer engine works differently.

1 Like

so you mean to say i should open the link of the website in chrome browser in webview , am i right

Nope. You have to define element more precisely.

Przechwytywanie

In my webviwer © 2021 Microsoft is 13th element.

oh i see

in chrome the 13 element is

now i got your point

is there any way i can set that the link opens in chrome only in webview

you are using firefox am i right

document.getElementsByClassName(“iscscd_data”)[0].innerText;

That’s the accurate solution - in my opinion :smiley:

1 Like

Have you tried it on the console of the website ?

document.getElementsByClassName('iscscd_data')[0].innerText;

It works for firefox and microsoft edge.

1 Like

hey i just tried it , it working in the console but not in my app , in my app it returns null

Works for me. You have to do the rest by yourself.