with the Ranorex.Control instance which is the expected argument to WebDocument.GetDocument(browserInstance) method?
From what I gathered looking around, I expect the the answer is to find the handle of the System.Windows.Forms.WebBrowser control instance and use it as the argument to the Ranorex.Control constructor - but I would prefer a definitive and complete answer to a lot of experimentation.
Thanks
Nik
Application.ShowForm =>System.InvalidOperationException
-
- Posts: 10
- Joined: Sun Oct 05, 2008 5:31 pm
- Location: Bellingham, WA, USA
- Contact:
-
- Posts: 10
- Joined: Sun Oct 05, 2008 5:31 pm
- Location: Bellingham, WA, USA
- Contact:
Relationship between System.Windows.Forms and Ranorex object
There is a (clearly intended) name collision - my previous post about the embedded WebBrowser control is just one example of the situation I do not completely understand. While it is obvious that you had to enhance the native browser control in order to be used in the context of your Automation environment, I am not sure what all the rules are and how are your own controls acquired from native ones (I do not expect to be able to use Ranorex Controls in the Visual Studio Designer for example, neither do I believe that you would like me to drop Visual Studio and use Ranorex Studio)
-
- Posts: 10
- Joined: Sun Oct 05, 2008 5:31 pm
- Location: Bellingham, WA, USA
- Contact:
Some more
Hello
Hoping to accelerate the process of making me understand the issues related to the embedded WebBrowser control, here is a section of code which shows my current problem. I have created a Ranorex.Control instance using the handle of the original WebBrowser control, navigated it to the proper page, and then executed the code which works perfectly with the external (not embedded) instance of IE 7. The code below fails at the line
The webElement is not found.
If the you need to actually run the code below, please let me know, so I can send you the needed password (stated as "xxxx" in the code)
Hoping to accelerate the process of making me understand the issues related to the embedded WebBrowser control, here is a section of code which shows my current problem. I have created a Ranorex.Control instance using the handle of the original WebBrowser control, navigated it to the proper page, and then executed the code which works perfectly with the external (not embedded) instance of IE 7. The code below fails at the line
Code: Select all
WebElement webElement = webDoc.FindSingle(userIDTextXPath);
If the you need to actually run the code below, please let me know, so I can send you the needed password (stated as "xxxx" in the code)
Code: Select all
private void SetupEmailServerView(WebBrowser browser, Uri uri)
{
bool rememberMeFlag = false;
LoginEmailAsAdministrator(browser, rememberMeFlag);
}
private void LoginEmailAsAdministrator(WebBrowser browser, bool rememberMe)
{
string userIDTextXPath = "//input[@id='ctl00_MPH_txtUserName']";
string passwordTextXPath = "//input[@id='ctl00_MPH_txtPassword']";
string languageComboXPath = "//select[@id='ctl00_MPH_LanguageList']";
string rememberMeCheckBoxXPath = "//input[@id='ctl00_MPH_chkAutoLogin']";
string loginButtonXPath = "//td[1]/div/a[@class='ButtonBarAnchor']";
string viewUsersXPath = "http://www.congral.net:9998/Default.aspx#page=/DomainAdmin/frmUsers.aspx?|section=UserSettings";
IntPtr bHandle = browser.Handle;
Ranorex.Control rBrowser = new Ranorex.Control(bHandle);
WebDocument webDoc = WebDocument.GetDocument(rBrowser);
webDoc.Navigate("http://www.congral.net:9998", true);
WebElement webElement = webDoc.FindSingle(userIDTextXPath);
Mouse.ClickWebElement(webElement, MouseButtonType.LeftButton, Alignment.Center, 0);
webElement.Value = "[email protected]";
webElement = webDoc.FindSingle(passwordTextXPath);
Mouse.ClickWebElement(webElement, MouseButtonType.LeftButton, Alignment.Center, 0);
webElement.Value = "xxxx";
if (rememberMe)
{
webElement = webDoc.FindSingle(rememberMeCheckBoxXPath);
Mouse.ClickWebElement(webElement, MouseButtonType.LeftButton, Alignment.Center, 0);
}
webElement = webDoc.FindSingle(languageComboXPath);
Mouse.ClickWebElement(webElement, MouseButtonType.LeftButton, Alignment.Center, 0);
webElement.Value = "en";
webElement = webDoc.FindSingle(loginButtonXPath);
Mouse.ClickWebElement(webElement, MouseButtonType.LeftButton, Alignment.Center, 0);
webDoc.Navigate(viewUsersXPath, true);
}
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Hi Nik,
As far as I understand from your description the attached code works fine within a standard browser but does not work within an embedded browser? Could you please clarify your problem.
Also, could you please provide me the login password at [email protected].
kind regards,
Christoph
Support Team
As far as I understand from your description the attached code works fine within a standard browser but does not work within an embedded browser? Could you please clarify your problem.
Also, could you please provide me the login password at [email protected].
kind regards,
Christoph
Support Team
-
- Posts: 10
- Joined: Sun Oct 05, 2008 5:31 pm
- Location: Bellingham, WA, USA
- Contact:
Additional problem clarification
I may have written incorrect code, guessing how to get the Ranorex.Control object from the instance of the Microsoft's embedded browser (WebControl) instance. So my current method to get the WebDocument for a given URL is
However, if instead of the above code I use:
the code snippet I posted works fine - as you can verify yourself, since I sent the missing password to you via email
Code: Select all
IntPtr bHandle = browser.Handle;
Ranorex.Control rBrowser = new Ranorex.Control(bHandle);
WebDocument webDoc = WebDocument.GetDocument(rBrowser);
webDoc.Navigate("http://www.congral.net:9998", true);
Code: Select all
WebDocument webDoc = WebDocument.OpenDocument("http://www.congral.net:9998", true)
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
I just tried to run your code and everything worked perfect with both the external browser and the embedded one. With the embedded browser you just need to be sure that the browser is displaying some website before you invoke the WebDocument.GetDocument() method; otherwise the document can't be found.
Regards,
Alex
Ranorex Support Team
Regards,
Alex
Ranorex Support Team
-
- Posts: 10
- Joined: Sun Oct 05, 2008 5:31 pm
- Location: Bellingham, WA, USA
- Contact:
Confirmed
My final code is:
Can you please verify that this is indeed the correct sequence and that all this code is needed (the immediate concern is the need to invoke the Navigate method twice)
Code: Select all
//
// Ensure that the WebBrowser control has page loaded
//
browser.Navigate(pageURL);
//
// Create the Ranorex.Control instance
//
IntPtr bHandle = browser.Handle;
Ranorex.Control rBrowser = new Ranorex.Control(bHandle);
//
// Create the WebDoument instance
//
WebDocument webDoc = WebDocument.GetDocument(rBrowser);
webDoc.Navigate(pageURL, true);
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Well, there might be a fundamental problem in your code: It seems that you call browser.Navigate(...) from your main window thread, i.e. in an EventHandler to a Form event. When you do that, the browser won't load and display the page immediately, but is only instructed to load that page. It will do that not until the event handler has been completely executed (windows message loop). So, when you execute the WebDocument.GetDocument(...) method some lines later, the browser will still not have a page loaded and the web document won't be found.
Either you initialize your web browser control with some web page by setting the Url property in the initialization and then wait for the document to be loaded before invoking your SetupEmailServerView method, or invoke it in an event handler to the WebBrowser.DocumentCompleted event.
Regards,
Alex
Ranorex Support Team
Either you initialize your web browser control with some web page by setting the Url property in the initialization and then wait for the document to be loaded before invoking your SetupEmailServerView method, or invoke it in an event handler to the WebBrowser.DocumentCompleted event.
Regards,
Alex
Ranorex Support Team