-
October 22nd, 2013, 11:13 PM
#1
WPF with WatiN plug in. need to open up IE and go to google
I need to make a WPF application in visual studio 2012 for desktop. Has to use the WatiN plug in. And I have to have a text box and button (which I have), That when you type in the text box and click the button the app will launch IE and go to google and search for whatever you typed into the text box and automatically select a link from the list of search results and go to that page. Any suggestions on how to do this? thank you!!!!!! I need answers ASAP.
-
October 23rd, 2013, 01:24 AM
#2
Re: WPF with WatiN plug in. need to open up IE and go to google
Based on the example from http://watin.org/ it seems pretty straightforward.
Add the NuGet WatiN package to your app and put in the sample code.
I got the following to work with a bit of effort:
Code:
using (var browser = new IE("http://www.google.com"))
{
browser.TextField(Find.ByName("q")).TypeText(_textBox.Text);
browser.Button(Find.ByName("btnG")).Click();
browser.WaitForComplete(5000);
System.Windows.Forms.SendKeys.SendWait("{ENTER}"); // presses search on the second screen
//browser.Button(Find.ById("gbqfb")/*.ByName("btnG")*/).Click(); // doesn't work
}
What have you tried? What doesn't work?
-
October 23rd, 2013, 09:49 AM
#3
Re: WPF with WatiN plug in. need to open up IE and go to google
I have not tried to much. I am new to WPF and am trying to teach myself how to do it. So i need someone to point me in the right direction or a walkthrough would be nice
-
October 23rd, 2013, 10:00 AM
#4
Re: WPF with WatiN plug in. need to open up IE and go to google
Originally Posted by Pope43
I have not tried to much. I am new to WPF and am trying to teach myself how to do it. So i need someone to point me in the right direction or a walkthrough would be nice
I just pointed you in the right direction, didn't?
-
October 23rd, 2013, 10:14 AM
#5
Re: WPF with WatiN plug in. need to open up IE and go to google
Well I would just like to know if i need to make any classes at all? or just put the functionality in my mainwindow.xaml.cs
-
October 23rd, 2013, 10:28 AM
#6
Re: WPF with WatiN plug in. need to open up IE and go to google
Originally Posted by Pope43
Well I would just like to know if i need to make any classes at all? or just put the functionality in my mainwindow.xaml.cs
No, the code that I posted earlier goes in the search button handler. That code uses a TextBox with a name of _textBox You'll need to use the xaml editor and drag a textbox from the toolbox to the designer surface. Then add Name="_textBox" to the generated xaml. Next drag a button onto the designer surface and double-click on it to generate a button handler. Switch to the code behind page and add the code from my snippet into the button handler.
-
October 23rd, 2013, 10:51 AM
#7
Re: WPF with WatiN plug in. need to open up IE and go to google
thank you I highly appreciate it
-
October 23rd, 2013, 10:55 AM
#8
Re: WPF with WatiN plug in. need to open up IE and go to google
I wrote the code out and did what you said but the name Find "does not exist in the current context"
Error 1 The type or namespace name 'IE' could not be found (are you missing a using directive or an assembly reference?) c:\users\user\documents\visual studio 2012\Projects\Search\Search\MainWindow.xaml.cs 30 38 Search
Error 4 The type or namespace name 'Forms' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?) c:\users\user\documents\visual studio 2012\Projects\Search\Search\MainWindow.xaml.cs 37 32 Search
-
October 23rd, 2013, 11:18 AM
#9
Re: WPF with WatiN plug in. need to open up IE and go to google
An unhandled exception of type 'System.IO.FileNotFoundException' occurred in WatiN.Core.dll
is the new error i get. I fixed the rest.
-
October 23rd, 2013, 02:50 PM
#10
Re: WPF with WatiN plug in. need to open up IE and go to google
It opens up IE and goes to google and types in what was in the text box into the search box but than the app closes. It doesnt search or select a link at random.
-
October 23rd, 2013, 04:21 PM
#11
Re: WPF with WatiN plug in. need to open up IE and go to google
Originally Posted by Pope43
It opens up IE and goes to google and types in what was in the text box into the search box but than the app closes. It doesnt search or select a link at random.
Hate to ask the obvious, but did you write code to select links at random? Now, I wouldn't have to ask this if you posted the code you have - generally speaking, it's a good idea to post code when asking questions in a programming forum as folks trying to help can see exactly what you are working with.
At any rate, given the nature of how the WatiN automation engine works, there might be differences in how various browser versions emit tags which could effect the reliability of the automation. I suggest you contact the folks at http://watin.org/ for more specific information on using their tool.
-
October 23rd, 2013, 04:45 PM
#12
Re: WPF with WatiN plug in. need to open up IE and go to google
this is the code i have. And no I have not written any code to select a link at random and i have no idea how to go about doing that either. I assume it will be in javascript. Can you please tell me the code that I will need to make my application do that?
using WatiN.Core;
namespace Search
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Btn_Click(object sender, RoutedEventArgs e)
{
using (var browser = new IE("http://www.google.com"))
{
browser.TextField(Find.ByName("q")).TypeText(_textBox.Text);
browser.Button(Find.ByName("btnG")).Click();
browser.WaitForComplete(5000);
System.Windows.Forms.SendKeys.SendWait("{Enter}"); // presses search on the second screen
browser.Button(Find.ById("gbqfb")/*.ByName("btnG")*/).Click(); // doesn't work
}
}
}
}
-
October 23rd, 2013, 06:29 PM
#13
Re: WPF with WatiN plug in. need to open up IE and go to google
Why would the code be in javascript when the rest of the code is in c#?
As far as solving the rest of the problem. Look on the WatiN sit for info how to capture a list of links. Then look for the Random class in msdn for how to use the random class. The put the two together.
-
October 23rd, 2013, 06:38 PM
#14
Re: WPF with WatiN plug in. need to open up IE and go to google
I dont know. I have a very basic understanding of WPF. abd ok thank you if you could provide links that would be great. I am trying to keep all my code on the same page
-
October 23rd, 2013, 06:48 PM
#15
Re: WPF with WatiN plug in. need to open up IE and go to google
could you explain on how to go about doing it? earlier you said that i would not need a class. so now i am a little bit confused
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|