Welcome Guest Search | Active Topics | Sign In | Register

EO.WebBrowser Auto-Fill and iFrame element C# Options
OlivierD
Posted: Wednesday, January 14, 2015 4:54:06 PM
Rank: Newbie
Groups: Member

Joined: 1/14/2015
Posts: 6
Hi,

I'm trying to auto-fill inputs to a site with a form in a iFrame.

I found this http://www.essentialobjects.com/forum/postsm35053_EOWebBrowser--auto-login--Vbnet.aspx

It works but there is a problem if my inputs are in a iFrame it's doesn't fill my inputs. I guessed it's because the url in my webView wasn't the one in the iFrame but in the global document. I tried webView.LoadUrlAndWait(urlofMyIFrame);. and after I used webView.EvalScript(evalscriptValue);. It doesn't work and it loads the document of the iFrame in my web browser as my main document. How can I auto-fill inputs in a iFrame and keep the main document in my web browser?

Also InnerText, like in the example in the link, doesn't contain a setter
Code: C#
EO.WebBrowser.DOM.Document doc = WebView1.GetDOMWindow().document;
doc.getElementById("username").innerText = user_name;


Thank you for your support.
eo_support
Posted: Wednesday, January 14, 2015 5:48:11 PM
Rank: Administration
Groups: Administration

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

In order to do this you must:

1. Set EnableWebSecurity browser option to false. For example, you can set it like this before creating any WebView:

Code: C#
EO.WebBrowser.BrowserOptions options = new EO.WebBrowser.BrowserOptions();
options.EnableWebSecurity = false;
EO.WebBrowser.Runtime.SetDefaultOptions(options);


2. You can then use something like this to fill input:

Code: C#
webView1.EvalScript("frames[frame_name].document.getElementById('user_name_id').value='user_name';");


Here you need to replace:

1. "frame_name" with the actual frame name;
2. "user_name_id" with the actual Id of the user name textbox;
3. "user_name" with the actual user name;

The key is use frame[frame_name].document to get the document object for the iframe. However in order to do so you must set EnableWebSecurity to false first.

Hope this helps. Please feel free to let us know if you still have any questions.

Thanks!
OlivierD
Posted: Thursday, January 15, 2015 5:16:46 PM
Rank: Newbie
Groups: Member

Joined: 1/14/2015
Posts: 6
Hi,

Thank you it works!

I also have another problem presented in this thread: http://www.essentialobjects.com/forum/postst8748_Circumvent-Content-Security-Policy.aspx

Thank you to let me know if you are going forward with the idea.
eo_support
Posted: Thursday, January 15, 2015 5:36:36 PM
Rank: Administration
Groups: Administration

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

These two are two different measures. This one is related to same origin script policy and it can be turned off. That one is is related to the header entry and it can affect not just JavaScript, but any kind of resource (images, font, CSS, etc) and it is not possible to turn it off. Another very important distinction is, EnableWebSecurity affects executing time behavior (JavaScript code from one origin can not access DOM from another origin) and is enforced by the JavaScript engine, where as Content-Security-Policy affects load time behavior and is enforced by the resource loader. So they are really very different.

Thanks!
OlivierD
Posted: Friday, January 16, 2015 8:33:01 AM
Rank: Newbie
Groups: Member

Joined: 1/14/2015
Posts: 6
Hi,

I was talking about an another website for Content Security Policy, not the one with iFrame, sorry about the confusion.
eo_support
Posted: Friday, January 16, 2015 1:28:32 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
No problem. Please feel free to let us know if you have any other questions.
Ioannis
Posted: Tuesday, May 17, 2016 2:24:31 PM
Rank: Newbie
Groups: Member

Joined: 5/13/2016
Posts: 5
FYI - the example code above seems to have changed...

In VB it is...

Dim options As New EO.WebEngine.BrowserOptions
options.EnableWebSecurity = False
EO.WebBrowser.Runtime.SetDefaultBrowserOptions(options)
eo_support
Posted: Tuesday, May 17, 2016 3:37:10 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Ioannis wrote:
FYI - the example code above seems to have changed...

In VB it is...

Dim options As New EO.WebEngine.BrowserOptions
options.EnableWebSecurity = False
EO.WebBrowser.Runtime.SetDefaultBrowserOptions(options)


Yes. Thanks for sharing!


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.