Welcome Guest Search | Active Topics | Sign In | Register

How to search and auto link click in eo web control??? Options
tuan
Posted: Thursday, October 9, 2014 9:20:29 PM
Rank: Member
Groups: Member

Joined: 10/9/2014
Posts: 19
hello eo_support! i'm using trial version!
here the code!
Code: C#
HtmlElementCollection eles = webwordpress.Document.GetElementsByTagName("A");
            foreach (HtmlElement btn in eles)
            {
                if (btn.InnerText == "search-text")
                {
                    
                    btn.InvokeMember("Click");
                }
            }

this use for webbrowser IE!

so....how to use with EO.WebBrowser for winform???

maybe i will to buy this control if my problem fixed! thanks!
tuan
Posted: Friday, October 10, 2014 1:22:53 AM
Rank: Member
Groups: Member

Joined: 10/9/2014
Posts: 19
no body help? @@
eo_support
Posted: Friday, October 10, 2014 10:43:32 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,218
Hi,

You will need to use something like this:

Code: C#
//Get the link collection
JSObject links = webView1.EvalScript("document.getElementsByTagName('a')") as JSObject;

//Get the number of elements in the collection
int count = links["length"] as int;

//Loop through the collection
for (int i = 0; i < count; i++)
{
    //Get the link element
    Element link = JSObject.CastTo<Element>(links[i]);

    //Check the innerText property and call click if needed
    string innerText = link["innerText"] as string;
    if (innerText == "search-text")
        innerText.InvokeFunction("click");
}


Hope this helps.

Thanks!
tuan
Posted: Friday, October 10, 2014 10:51:05 AM
Rank: Member
Groups: Member

Joined: 10/9/2014
Posts: 19
thanks for the feedback my question ! I will try now !
By the way I want to ask the trial version limits what ?
thanks
tuan
Posted: Friday, October 10, 2014 11:09:30 AM
Rank: Member
Groups: Member

Joined: 10/9/2014
Posts: 19
error:

Error 1 Cannot implicitly convert type 'object' to 'EO.WebBrowser.JSObject'. An explicit conversion exists (are you missing a cast?)

i thing you need make demo for my problem! :D

eo_support
Posted: Friday, October 10, 2014 11:18:41 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,218
Hi,

I apologize for the mistake. You need to add "as JSObject" at the end, and also change JSObject.CastTo to JSObject.CastTo<Element>.

You can not legally use the trial version for production. Also the trial version displays a trial banner.

Thanks!
tuan
Posted: Friday, October 10, 2014 11:25:05 AM
Rank: Member
Groups: Member

Joined: 10/9/2014
Posts: 19
hey! more error here!

http://www.upsieutoc.com/image/ne9V

i recomeded you make app demo! :@@
eo_support
Posted: Friday, October 10, 2014 11:29:22 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,218
Hi,

You need to read and understand the code instead of just copy and paste. We are not here to write code for you. We only show you how to do it, you need to read the documentation and understand why it's done that way and then adapt the code to fit your own need. The sample code we gave you to make extensive use of JSObject and EvalScript. You can find more information about them here:

http://www.essentialobjects.com/doc/6/advanced/js.aspx

Thanks!
tuan
Posted: Friday, October 10, 2014 11:33:28 AM
Rank: Member
Groups: Member

Joined: 10/9/2014
Posts: 19
I clearly understand what you code !
serious errors in your code here !
Invoke string it can do ?

Code: C#
//Check the innerText property and call click if needed
                string innerText = link["innerText"] as string;
                if (innerText == search)
                    innerText.InvokeFunction("click");


I do not understand !
Why are you not code the properties , functions ... etc just like IE for users to use , but the entire complex ones !
eo_support
Posted: Friday, October 10, 2014 11:36:38 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,218
Hi,

Yes. You are right. It should be link.InvokeFunction. This is the function you should call:

http://www.essentialobjects.com/doc/6/eo.webbrowser.jsobject.invokefunction.aspx

Thanks

tuan
Posted: Friday, October 10, 2014 6:59:22 PM
Rank: Member
Groups: Member

Joined: 10/9/2014
Posts: 19
While you are the author of this control , but you is not possible to reconcile my problem ! Then you re- write a few lines of code without error a lot of tests before post them here ... copy and pase , but I also know the fix ! but the control library does not contain it .... and said " we do not code for you but show you how to do it right .... " while I'm newbie , could also be customers of you .... your job is to solve my problem !
eo_support
Posted: Friday, October 10, 2014 9:31:04 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,218
Hi,

We apologize for having mistakes in our sample code. We did clearly told you what we changed when we modify the code. Once again, we do expect you to put in reasonable effort to try to understand the code and follow the documentation we provided to you.

In the future please try to maintain a friendly and constructive tone with your post and focus on the technical aspect of things since this is a tech support forum. We will work with you if you work with us. However if you do not want to follow our instructions or are unwilling to put in the effort on your part, we will have no problem to ask you to leave. Remember you have the right to choose any product or vendor you want, but you do not have any right to demand any service here. We will have no problem to refuse service to you if we believe your behavior is inappropriate or harmful either to us or to other customers. The forum is a resource to all our customers, so we will not tolerate such flameful post in the forum from you again. Please regard this as a warning, in the future we will delete such post without notice.

Thanks
ac2015
Posted: Thursday, December 24, 2015 8:09:19 AM
Rank: Member
Groups: Member

Joined: 12/24/2015
Posts: 14
Unfortunately the code below is buggy and actually not working.
I have the same problem.

eo_support wrote:
Hi,

You will need to use something like this:

Code: C#
//Get the link collection
JSObject links = webView1.EvalScript("document.getElementsByTagName('a')") as JSObject;

//Get the number of elements in the collection
int count = links["length"] as int;

//Loop through the collection
for (int i = 0; i < count; i++)
{
    //Get the link element
    Element link = JSObject.CastTo<Element>(links[i]);

    //Check the innerText property and call click if needed
    string innerText = link["innerText"] as string;
    if (innerText == "search-text")
        innerText.InvokeFunction("click");
}


Hope this helps.

Thanks!
eo_support
Posted: Thursday, December 24, 2015 3:17:12 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,218
ac2015 wrote:
Unfortunately the code below is buggy and actually not working.
I have the same problem.

eo_support wrote:
Hi,

You will need to use something like this:

Code: C#
//Get the link collection
JSObject links = webView1.EvalScript("document.getElementsByTagName('a')") as JSObject;

//Get the number of elements in the collection
int count = links["length"] as int;

//Loop through the collection
for (int i = 0; i < count; i++)
{
    //Get the link element
    Element link = JSObject.CastTo<Element>(links[i]);

    //Check the innerText property and call click if needed
    string innerText = link["innerText"] as string;
    if (innerText == "search-text")
        innerText.InvokeFunction("click");
}


Hope this helps.

Thanks!


The code is correct for the purpose of the original question. Your question is slightly different and we have already replied it in a different thread. Please do not post the same question in multiple threads in the future.

Thanks!
Anthiel
Posted: Wednesday, March 4, 2020 6:25:38 PM
Rank: Newbie
Groups: Member

Joined: 2/14/2020
Posts: 7
eo_support wrote:
ac2015 wrote:
Unfortunately the code below is buggy and actually not working.
I have the same problem.

eo_support wrote:
Hi,

You will need to use something like this:

Code: C#
//Get the link collection
JSObject links = webView1.EvalScript("document.getElementsByTagName('a')") as JSObject;

//Get the number of elements in the collection
int count = links["length"] as int;

//Loop through the collection
for (int i = 0; i < count; i++)
{
    //Get the link element
    Element link = JSObject.CastTo<Element>(links[i]);

    //Check the innerText property and call click if needed
    string innerText = link["innerText"] as string;
    if (innerText == "search-text")
        innerText.InvokeFunction("click");
}


Hope this helps.

Thanks!


The code is correct for the purpose of the original question. Your question is slightly different and we have already replied it in a different thread. Please do not post the same question in multiple threads in the future.

Thanks!


Dear Support-Team :)
I did try this code (also some others), but sadly it doesn't work.
I want also "just" to find and press a button.

Issues (without even starting, I had to comment them out to test the rest):

1. int count = links["length"] as int;
Doesn't work ; Error: CS0077 ; WF_EO_WebBrowser C:\Users\Me\source\repos\WF_EO_WebBrowser\WF_EO_WebBrowser\EO_Browser.cs;
Description: NULL-Value is not allowed;
"links" is NOT empty, I can manually go thought the list for example:
Code: C#
Element link = JSObject.CastTo<Element>(links[2]);
string innerText = link["innerText"] as string;

"innetText" has a usefull string.

2. innerText.InvokeFunction("click");
Doesn't work; No Error Code;
Description: innerText has no definition for "InvokeFunction";
If I use "innerText." and then intellisense I can't find "InvokeFunktion" just a list of not similar stuff :/

I also used the doc page but couln't find anything that helps.
Btw. if I use "https://www.whatismybrowser.com" I have "Chrome 77", not IE like the original questioner said.
Also maybe useful: I use "webControl" "EO.WinForm.WebControl"
My active using's:
Code: C#
using EO.WebBrowser;
using EO.WebBrowser.DOM;
using System;
using System.Windows.Forms;


It would be also super awesome if I could get also a example for entering text after I found the right text-field/textBox.
Or should I open a new thread for that?

Thanks already for any help :)
eo_support
Posted: Wednesday, March 4, 2020 9:11:22 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,218
Hi,

The recommanded method for such situation is to use JavaScript code. So instead of making multiple .NET calls, you would make a single .NET EvalScript call instead and everything else would be in the JavaScript code. The code will be something like this:

Code: C#
webView.EvalScript("(function()
{
    var links = document.getElementsByTagName('a');
    for (var i = 0; i &lt; links.length; i++)
    {
        .....
    }
})()");


The key here is all the logic are in the JavaScript code you passed to EvalScript. The basic construct of the code is:

Code: C#
webView.EvalScript("(function()
{
    ...JavaScript code
})();");


Here the JavaScript code is enclosed inside an anonymous function so that variables used in your code won't conflict with anything else. Since the exact logic would be completely implemented in JavaScript code, you can search online for how to implement exactly what you need to do.

Thanks!
Anthiel
Posted: Thursday, March 5, 2020 12:30:19 PM
Rank: Newbie
Groups: Member

Joined: 2/14/2020
Posts: 7
Thanks for the fast answer ! :)

But sadly that didn't help me.
Even if the code would work, there is no option to watch into the variables while debugging.
Is there an C# only way or at least a way with less JavaScript?

If not, could you please send me at least one examlpe code which is tested and working ?
Because the posted code just doesnt work and I played and tested our much with this small piece of code, still nothing works.

For example:

Code: C#
webView1.EvalScript("(Function()" +
"{" +
    "var links = document.getElementsByTagName('button');" +
    "for (var i = 0; i &lt; links.lenght; i++)" +
    "{" +
        "if (item.outerHTML.Contains(\"class=\"XYZ\"))" +
        "{" +
            "item.InvokeFunction(\"click\");" +
        "}" +
    "}" +
"}) ()", true);
eo_support
Posted: Thursday, March 5, 2020 1:03:29 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,218
Hi,

We only show you the idea. You will need to work out the exact code yourself. If we were to write the actual code for our customer, then all our customers will just tell us what they need to do and ask us to write code for them. Obviously we won't be able to do that. So the answer to your request about "example code which is tested and working" is a BIG NO.

If you have questions while trying to understanding the sample code we provided to you on the .NET side directly related to our product, we will be happy to help you further. Again any question about JavaScript code, including questions like how to debug JavaScript code, you will need to resolve yourself.

You will definitely need to familiar yourself with JavaScript code and also work out your logic first. There are obvious problems in your code:

1. There is no InvokeFunction in JavaScript. This is a .NET function on our .NET objects. It does not exist in JavaScript;
2. I am not sure how you can "click" ALL the links ---- because as soon as you click the first link in the page, the page will immediately redirect to another page. This means from this moment everything in the original page (for example, the remaining 9 links of all the 10 links) will no longer be valid;

So you definitely need to work out those first.

Thanks!
Anthiel
Posted: Friday, March 6, 2020 7:22:57 PM
Rank: Newbie
Groups: Member

Joined: 2/14/2020
Posts: 7
I see/understand, thanks :)

To point 2. My example "class=\"XYZ\"" would be only one time found on this page, but it was anyway just a test code to see if I get it running.
Ofc I would simply add a "break;" even if it is not needed, at least not in my case.

I dont want to bother/take to much time of you hehe.

Is there a C# only or a less JavaScipt way?
If yes where can I find sample codes?

Ofc it would be to time consuming if you help everyone with the code, but where are the samples then?
I can google it bcs it "ur" own code.

Mybe I didn't see something usefull in the docs?

Also I found this on this forum:

Code: C#
EO.WebBrowser.DOM.Element[] elems = 
    webControl1.WebView.GetDOMWindow().document.getElementsByTagName("a");

foreach (EO.WebBrowser.DOM.Element elem in elems)
{
    ....
}


But it seems that this code also isn't the right for me :/
eo_support
Posted: Tuesday, March 10, 2020 10:13:02 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,218
I am not sure what else we can tell you. You need to do this with JavaScript. You keep ignoring that and trying to find a way around it. There is no point for us to support you if you don't follow what we tell you.


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.