How to wait for web page fully loaded then open/create new form2 with webbrowser navigate to another page
I'm trying by checking using igetattribut on loaded site on form 1 but not working because checking is running before web fully loaded
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace bot
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
webbMain.Navigate("http://asia1.darkorbit.com/");
}
private void btnLogin_Click(object sender, EventArgs e)
{
var inputElements = webbMain.Document.GetElementsByTagName("input");
foreach (HtmlElement i in inputElements)
{
if (i.GetAttribute("name").Equals("username"))
{
i.InnerText = txtUsername.Text;
}
if (i.GetAttribute("name").Equals("password"))
{
i.Focus();
i.InnerText = txtPassword.Text;
}
}
var buttonElements = webbMain.Document.GetElementsByTagName("input");
foreach (HtmlElement b in inputElements)
{
if (b.GetAttribute("className").Equals("bgcdw_button bgcdw_login_form_login"))
{
b.InvokeMember("click");
}
}
}
}
}
Related
I am developing a software in C #, and I need to list the names of the available serial ports, but when using (PortName ()) the Visual Studio does not recognize the (PortName ()) and the error. What could be wrong? I'm using Visual Studio 2019 and C #.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Control
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void ListCOMs()
{
int i;
bool qtde;
i = 0;
qtde = false;
if (cbPorts.Items.Count == mySerialPort.PortName().Length)
{
foreach (string s in mySerialPort.PortName())
{
if (cbPorts.Items[i++].Equals(s) == false)
{
qtde = true;
}
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void timerCOM_Tick(object sender, EventArgs e)
{
ListCOMss();
}
}
}
Thanks
The web page is:
Google Tennis Results
What i'm trying to get as text is the tennis results in the top of the page.
Tried using webBrowser now but not getting it at all.
Not sure if it's also java script in the page or not but i can't parse it.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Net;
using System.Threading;
using System.Runtime.InteropServices;
namespace Test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
test1();
}
private void test1()
{
this.webBrowser1.ObjectForScripting = new MyScript();
}
[ComVisible(true)]
public class MyScript
{
public void CallServerSideCode()
{
var doc = ((Form1)Application.OpenForms[0]).webBrowser1.Document;
var renderedHtml = doc.GetElementsByTagName("HTML")[0].OuterHtml;
}
}
private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.Navigate("https://www.google.co.il/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=australian%20open%20atp");
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
webBrowser1.Navigate("javascript: window.external.CallServerSideCode();");
}
}
}
I have some problems to use the MSTSCLib to connect from 1 PC to another one.
It's working with Servers but not with normal Workstations...
private void btn_connect_Click(object sender, EventArgs e)
{
try
{
rdp_control.Server = tbx_servername.Text;
rdp_control.Connect();
tabPage1.Text = "Connected";
}
catch (Exception exp)
{
MessageBox.Show(exp.ToString());
}
}
private void btn_disconnect_Click(object sender, EventArgs e)
{
if (rdp_control.Connected.ToString() == "1")
{
rdp_control.Disconnect();
}
}
Both client and server applications are in the Same Network under the same NAT. Problem is the certificate,... I need to find a way to include the certificate. With the normal Remote Desktop from Windows, you see a MessageBox with the question:"Do you want to use this certificate.... blablabla" But this is not coming up with the RDP function in c#
Any Ideas?
Thanks B.R.
Following code shows a simple RDP client and server.
RDP Server
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using RDPCOMAPILib;
using AxMSTSCLib;
using System.Runtime.InteropServices;
namespace TCP_to_RDP_Converter
{
public partial class Form1 : Form
{
public static RDPSession currentSession = null;
public static void createSession()
{
currentSession = new RDPSession();
}
public static void Connect(RDPSession session)
{
session.OnAttendeeConnected += Incoming;
session.Open();
}
public static void Disconnect(RDPSession session)
{
session.Close();
}
public static string getConnectionString(RDPSession session, String authString,
string group, string password, int clientLimit)
{
IRDPSRAPIInvitation invitation =
session.Invitations.CreateInvitation
(authString, group, password, clientLimit);
return invitation.ConnectionString;
}
private static void Incoming(object Guest)
{
IRDPSRAPIAttendee MyGuest = (IRDPSRAPIAttendee)Guest;
MyGuest.ControlLevel = CTRL_LEVEL.CTRL_LEVEL_INTERACTIVE;
}
/// <summary>
/// Handle the form items
/// </summary>
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
createSession();
Connect(currentSession);
textConnectionString.Text = getConnectionString(currentSession,
"Test","Group","",5);
}
private void button2_Click(object sender, EventArgs e)
{
Disconnect(currentSession);
}
}
}
In order to use the RDP communication library you need to add rdpcompapi and Microsoft windows terminal services, form the COM references.
RDP Client
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using RDPCOMAPILib;
using AxRDPCOMAPILib;
namespace Simple_RDP_Client
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static void Connect(string invitation, AxRDPViewer display, string userName, string password)
{
display.Connect(invitation, userName, password);
}
public static void disconnect(AxRDPViewer display)
{
display.Disconnect();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
Connect(textConnectionString.Text, this.axRDPViewer, "", "");
}
catch (Exception)
{
MessageBox.Show("Unable to connect to the Server");
}
}
}
}
you can add reference to the AxRDPCOMAPILib by importing RDP viewer class component to the main form.
Full project can be downloaded from here [Download]:http://sandaruwmp.blogspot.com/2014/05/remote-desktop-application-with-rdp.html
use this....
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MSTSCLib;
namespace RemoteTool
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
MSTerminalServiceControl1.Server = textBox1.Text;
MSTerminalServiceControl1.UserName = textBox2.Text;
IMsTscNonScriptable secured = (IMsTscNonScriptable)MSTerminalServiceControl1.GetOcx();
secured.ClearTextPassword = textBox3.Text;
MSTerminalServiceControl1.Connect();
}
private void button2_Click(object sender, EventArgs e)
{
MSTerminalServiceControl1.Disconnect();
}
}
}
I am creating a simple web-browser reloader program. In my program I am using these controls
axMozillaBrowser,
Button,
progressBar,
TextBox
I am trying to load a web page "5" times. Below is my code that works when i use webBrowser control (an instance of internet explorer)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
while (progressBar1.Value !=5 )
{
webBrowser1.Navigate(textBox1.Text);
while(webBrowser1.ReadyState != webBrowserRedyState.Complete)
{
if (webBrowser1.ReadyState == webBrowserRedyState.Complete)
{
progressBar1.Value =+ 1;
}
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
progressBar1.Maximum = 5;
textBox1.Text = "www.google.com";
}
}
}
This is the code that is not working when I use axMozillaBrowser control (an instance of Mozilla Browser). This doesn't load the web page and it's waiting cursor is just blinking.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
while (progressBar1.Value !=5 )
{
axMozillaBrowser1.Navigate(textBox1.Text);
while(axMozillaBrowser1.ReadyState != MOZILLACONTROLLib.tagREADYSTATE.READYSTATE_COMPLETE)
{
if (axMozillaBrowser1.ReadyState == MOZILLACONTROLLib.tagREADYSTATE.READYSTATE_COMPLETE)
{
progressBar1.Value =+ 1;
}
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
progressBar1.Maximum = 5;
textBox1.Text = "www.google.com";
}
}
}
Does your browser control have Navigated (or something like that) event?
As example, you can use it into simple logic cycle, where your control navigates to first URL in collection, then, when navigation completed, navigate to second URL and next.
upd: sorry, I read it again and can't understand now.
upd2: but I suggest you to find Navigated and Navigating events and NavigationState property.
I have a C# Web Browser, I am trying to access: my.screenname.aol.com for mail, but it won't even load, I don't have much code...as you can see:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace EmailViewer
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
timer1.Enabled = false;
webBrowser1.Navigate("my.screenname.aol.com");
}
}
}
It's worth a shot to try WebBrowser.ScriptErrorsSuppressed Property to true.