I have a problem with a GetElementById function.
I was looking for tutorial "how to make auto login" aplication and I noticed everyone is getting submission while typing .Get... (screen 1). That's how it look in my aplication (screen 2).
When I try use full function it gets this message (screen 3).
I think there can be problem with missing library or something like that.
Screen 1Screen 2Screen 3
You'll need to add a reference to mshtml:
using mshtml;
Then in your event handler:
private void Button_Click(object sender, RoutedEventArgs e)
{
HTMLDocument document = (HTMLDocument)WebBrowser1.Document;
IHTMLElement element = document.getElementById("email");
}
Related
I have a main form that opens a new form that contains a web browser control that navigates to the entered url when it is loaded. I've tried different things I've found and this is my latest code: I have a function (GoToURL) that is triggered at the Shown event of the form which is here:
public delegate void Launch();
private void launchBrowser()
{
webBrowser1.Navigate(GlobalData.URL);
}
private void GoToURL(object sender, EventArgs e)
{
webBrowser1.Invoke(new Launch(launchBrowser));
}
I have nothing in the Document Completed function:
void browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
}
The web browser control loads the url just fine and I can scroll around in it, but on some links or buttons the control goes white and nothing happens. It won't proceed with the desired function. A more specific example is I am logging into a site and once I click the submit button it just hangs there. A "loading" image is presented and it just sits there. I know the Document Completed function above is triggered when this happens, too.
I apologize for my inexperience with C# and this is the first time using the web browser control (forms not wpf), so I am at a loss of what to try. I suspect its a threading issue, but that's as far as I got.
You are experiencing issues within the browser itself. Please launch IE and test the same there. I suspect you'll see the same issues.
Your experience is tied to the version of Internet Explorer you have in your system, and javascript errors have been frequents in the earlier versions of IE. Upgrade to IE11 in any case.
If that's not an option, try using a browser control with a different rendering engine. I'm too lazy to find and list the options, but I've used a few and they work well.
to avoid JavaScript Errors please follow this
public frmMain()
{
//Java Script Error popup block
webBrowser1.ScriptErrorsSuppressed = true;
}
Please Check this on loading Uri using
webBrowser1.Url = new Uri(Url.Trim().ToString());
Url - your desired Url
I need to change the BackgroundImage of a button on click of another button (In Windows Forms in C#). But I can't find out how to do it!!
I searched on the internet and found many examples and all of them use ImageBrush, ImageSource etc.... but these don't work on my application, it shows me errors every time I Use them.
I read on the internet that I have to add this namespace:
using Windows.UI.Xaml.Media.Imaging;
But it shows me an error on the begging which says to add this System before Windwons and when I add it:
using System.Windows.UI.Xaml.Media.Imaging;
it shows me than the error at UI .... I can't figure it out how to solve this!!
Please help me guys!
To Change Background Image of a button there are two ways i know.
Add the Image to the resources folder of your project and use.
private void button2_Click(object sender, EventArgs e)
{
button1.BackgroundImage = Properties.Resources.ImageName;
}
Use Image.FromFile();
private void button2_Click(object sender, EventArgs e)
{
button1.BackgroundImage = Image.FromFile(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + "//Card1.png");
}
You are trying to use solutions for WPF in Winforms. This will not work.
The class you need is System.Drawing.Image (or System.Drawing.Bitmap, which inherits from Image).
Bitmap b = new Bitmap(#"C:\myBitmap.jpg");
myButton.Image = b;
Be sure to call Dispose on your Bitmap if and when it is no longer in use.
I have a project that I'm doing with
Microsoft VSTO (office 2013 excel)
I have certain things that make calls that take maybe 10 seconds to come back.
Ideally I would like to display an progress bar or some status... After a lot of searching I found an article that is titled:
How do I create a splash screen window for the VSTO applications?
http://www.datazx.cn/Fv7p5a/xw/oa2v/2q7xs6/mcccjfti-988m-f8r8-8d44-bstb4rfsi4xm23rsdfd.html
So I started creating this code in a form, but then I realize that I need to call it up within my methods and really attach events etc...
The article says to
"display a modal form on a background thread" What is the best way to do this?
I find it easier to use modal less form on main thread and so far haven't seen any problem with modal less approach. Something like code below
var splashWindow = new SplashWindow();
splashWindow.Show();
splashWindow.SetMessage("Starting please wait...");
DoSomeWork(splashWindow);
splashWindow.Close();
Following you will see a way I programmed a Splash Screen for Excel-VSTO in C#. My Excel file is enabled for macros (.xlsm). These are the steps:
Create your splash screen. Let's assume the name of the form is SplashScreen.
Go to the code of the object ThisWorkbook.cs
Check the code looks like:
public partial class ThisWorkbook
{
SplashScreen SC = new SplashScreen();
private async void ThisWorkbook_Startup(object sender, System.EventArgs e)
{
SC.Show();
await Task.Delay(3500);
SC.Close();
more code...
}
}
It is important that you notice that I added the word async to the subroutine.
private void ThisWorkbook_Startup(object sender, System.EventArgs e)
I hope this is very useful.
I have a c# program which has a web browser my program deals with java pages i want it to click a button in a page but the button has no ID or value all i got about it is this code :
td class="submit">
<br>
<button class="fixedSizeBigButton" type="submit">
</td>
please is there any way to click that button
and for http://watin.sourceforge.net/ i need a code
thanks a lot
Your button has a class name,you can find your button using class name,see this example:
private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.DocumentText = "<td class=\"submit\"><br><button class=\"fixedSizeBigButton\" type=\"submit\"></td>";
webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
}
void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
foreach (HtmlElement btn in webBrowser1.Document.GetElementsByTagName("button"))
{
if (btn.GetAttribute("ClassName") == "fixedSizeBigButton")
{
btn.InvokeMember("Click");
}
}
}
I found this link when I went looking around.
More looking around leads me to believe you need to look more into the entire Find class itself. I know there are other ways to locate elements.
I'm trying to locate the documentation that will let me construct some code, since I've never actually used this before :-) I'll update if/when I get something more.
Update
Looks like you aren't the only one having similar issues. You can apparently Chain find methods. WatiN - Find HTML Table Which seems rather useful, if you know more about the button's exact location. Using Find.ByClass along with something else, to try to define the button uniquely.
I'm trying to write a silverlight application that takes in InitParams and then uses those InitParams to make a change to the Source of the MediaElement on the page. I'm trying to figure out the proper place to put my code.
I watched Tim Heuer's excellent video on InitParams, but in the video (which was for Silverlight 2), it shows the following on the Page.xaml.cs:
void Page_Loaded(object sender, RoutedEventArgs e)
{
}
I don't see Page_Loaded when I open MainPage.xaml.cs, and I'm wondering if that was automatically created in the Silverlight 2 SDK and left out of the Silverlight 3 SDK. Or perhaps Tim added that in his video manually.
I find that I can go into the opening UserControl tag of MainPage.xaml and add Loaded="<New_Event_Handler>" which creates the following in MainPage.xaml.cs:
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
}
By default, there's also the following in MainPage.xaml.cs, which is run during the Application_Startup event in App.xaml.cs:
public MainPage()
{
InitializeComponent();
}
I need to figure out where is the best place to insert my code to change the Source on my MediaElement in my xaml. Should I put it in MainPage? Should I add the Loaded event handler and put it into UserControl_Loaded? If it's supposed to be Page_Loaded, where do I find that in Silverlight 3?
Any help would be much appreciated.
"UserControl_Loaded" and "Page_Loaded" are just method names and the names don't matter (you could name the method "Foo" if you wanted). What makes these methods do anything is the fact that they are attached to the Loaded event on the UserControl (which is what you did when you edited the MainPage.xaml file).