Page 1 of 2

problem with BrowserSetElement

PostPosted: Wed Aug 27, 2014 1:04 pm
by mohsen.zeus
Greetings
I am using BrowserGetElement ، BrowserSetElement action code
And I want to show the result_box from translate.google.com/?hl=en&tab=wT
but i cant show result translate in neobook :|
how it can be added? :!:

Re: problem with BrowserSetElement

PostPosted: Thu Aug 28, 2014 4:02 am
by mohsen.zeus
No one came to help me?
:(

Re: problem with BrowserSetElement

PostPosted: Thu Aug 28, 2014 6:37 am
by Tony Kroos
Browser(Set/Get)Element has no problem and nothing to do here. They work only for elements with "NAME" tag.
Code: Select all
BrowserExecScript "WebBrowser1" "var i = document.getElementById('result_box').getElementsByTagName('span');|var t = '';for(var j=0; j<i.length; j++){t += i(j).textContent+' '};|window.external.nbSetVar('Google',t)" "JScript"

Re: problem with BrowserSetElement

PostPosted: Thu Aug 28, 2014 6:57 am
by mohsen.zeus
Thank you for the answer
I'm amateur
If possible More explain .
I just want to show translated result in label .
thank you again

Re: problem with BrowserSetElement

PostPosted: Thu Aug 28, 2014 7:18 am
by Tony Kroos
What exactly you did not understand? Open your link in neobook's WebBrowser object, then execute BrowserExecScript code for that object and you will get result in [Google] variable.

Re: problem with BrowserSetElement

PostPosted: Thu Aug 28, 2014 8:17 am
by mohsen.zeus
sorry but realy i don't know how to use this code
can you make a simple pub for me ?

Re: problem with BrowserSetElement

PostPosted: Thu Aug 28, 2014 10:32 am
by Neosoft Support
Hi Mohsen,

There is a sample publication included with NeoBook called "Browser Elements.pub" which you should find in your documents folder under "NeoBook 5\Sample Apps\Browser Communication". This pub demonstrates how to use the BrowserSetElement action.

Re: problem with BrowserSetElement

PostPosted: Thu Aug 28, 2014 11:30 am
by dpayer
mohsen.zeus wrote:sorry but realy i don't know how to use this code
can you make a simple pub for me ?


First, you should always show what you have already done before asking for someone to do something for you. Post your sample that didn't work as you expected or the actions you used.

I could not get this to work either.

I looked at this and the element that contains the resultant translation is not easy to find. the Div does have an ID and when I inspect the element in Firefox it shows the style of the translated area to be "result_box". When I look in the source HTML I see that this style is being applied against the textarea field named edit-text.
Code: Select all
<span id=result_box class="short_text"></span></div></div><div id="gt-edit" style="display:none"><div style="width: 100%;"><textarea id=contribute-target name=edit-text wrap=SOFT tabindex=0 spellcheck="false" autocapitalize="off" autocomplete="off" autocorrect="off" ></textarea></div>


When I create a pub that lets you put the translate page in a webbrowser object and then you put in text to translate. THat works ok. But if I attempt to get element by name, it does not get the content of that text entry element. Here is my sample pub. (Create a new pub 800x600 and paste this content into it)
Code: Select all
 {NeoBook 5 Objects}
NeoBookVer=5.80
ObjectType=14
Name=WebBrowser1
X=11
Y=15
W=777
H=407
Anchor=0
FileName=about:blank
VarName=[WebBrowser1Status]
TitleVarName=[WebBrowser1Title]
URLVarName=[WebBrowser1Addr]
LineColor=0
LineWidth=1
LineStyle=0
FillColor=12632256
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=2
ObjectType=3
Name=PushButton1
X=19
Y=439
W=158
H=39
Anchor=0
Text=Go To Translate
Align=2
ImageStyle=0
ObjAction=BrowserGoTo "WebBrowser1" "https://translate.google.com"¶EnableObject "PushButton2"
LineColor=0
LineWidth=1
LineStyle=0
FillColor=12632256
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=3
ObjectType=3
Name=PushButton2
X=627
Y=435
W=158
H=39
Anchor=0
Text=Get Translation
Align=2
ImageStyle=0
ObjAction=BrowserGoTo "WebBrowser1" "https://translate.google.com"¶BrowserGetElement "WebBrowser1" "edit-text" "[result]"¶AlertBox "Translation" "This is the translated text:|[result]"
LineColor=0
LineWidth=1
LineStyle=0
FillColor=12632256
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
Enabled=No
TabOrder=4

Image
I use this action on the page that has the translated text:

BrowserGetElement "WebBrowser1" "edit-text" "[result]"

When enacted on the page that contains the translation, the result variable is empty and the google translate page clears itself and resets.

David P.

Re: problem with BrowserSetElement

PostPosted: Thu Aug 28, 2014 11:43 am
by mohsen.zeus
tnq so much dpayer
how can find button in site browser element
Because browserElement just have text field

Re: problem with BrowserSetElement

PostPosted: Thu Aug 28, 2014 12:04 pm
by dpayer
mohsen.zeus wrote:tnq so much dpayer
how can find button in site browser element
Because browserElement just have text field


Mohsen,

I guess you didn't realize from my post that I too have a problem getting the text to be returned from the browsergetelement action.

I think we both need someone with additional javascript knowledge or someone who can give a new idea. You shouldn't need the button to give you text, we should be able to retrieve it by obtaining the value of the element.

David P.

Re: problem with BrowserSetElement

PostPosted: Thu Aug 28, 2014 5:05 pm
by David de Argentina
Be carefull using Google services !

They are free for final users, not for programmers.

Take a look of this:

viewtopic.php?f=1&t=20296&p=11212334

My defaulted cent,
David de Argentina

Re: problem with BrowserSetElement

PostPosted: Thu Aug 28, 2014 8:42 pm
by Tony Kroos
Looks like we have different Googles )

Image

When I look in the source HTML I see that this style is being applied against the textarea field named edit-text.

I guess you won't find results here (and source string either), since it's dynamically generated content. Try to use "Inspect code" option to see generated content on-the-fly.
Also, Browser(GEt/Set)Element works only with source code of the page. So no wonder if it doesnt work for dynamic content handled by the browser itself, it just cannot be seen by Browser(GEt/Set)Element.

p.s: I admit that my JS code doesnt work for your sample pub ) Looks like it's another google code for different languages or smth... will research more )

EDIT: Uncheck "Enchanced security" and "IE7 compatibility" options in WebBrowser object, and JS works just fine. - http://oi59.tinypic.com/9gll5c.jpg

Re: problem with BrowserSetElement

PostPosted: Thu Aug 28, 2014 11:08 pm
by mohsen.zeus
Thank you all
so can not build a dictionary with google
Now I have a question
i need a app use a website for show mobile model with number phone
http://92.42.49.87:8080/mtn_ir-dms-scw/ ... tlocale=en
this site is for iran
how can i make this app it posibble ?

Re: problem with BrowserSetElement

PostPosted: Fri Aug 29, 2014 6:48 am
by dpayer
Tony Kroos wrote:Also, Browser(GEt/Set)Element works only with source code of the page. So no wonder if it doesnt work for dynamic content handled by the browser itself, it just cannot be seen by Browser(GEt/Set)Element.
EDIT: Uncheck "Enchanced security" and "IE7 compatibility" options in WebBrowser object, and JS works just fine. - http://oi59.tinypic.com/9gll5c.jpg


Good work Tony. That does give the desired result.

David P.

Re: problem with BrowserSetElement

PostPosted: Tue Mar 29, 2016 4:16 pm
by Wrangler
I can use this function. Tony shows a screenshot that it is working, but I can't get it to work. Pasted in David's browser code. Unchecked Enhanced Security. The variable is empty. What was done with the code to make this work?