【发布时间】:2016-02-11 16:44:55
【问题描述】:
我最近开始了一个新项目,它与默认的 Visual Studio 2015“webBrowser”一起正常工作。不幸的是,默认浏览器不支持我需要它运行的一些网络元素。因此,我决定寻找可以运行这些元素的浏览器替代方案。
在做了一些研究后,我决定使用 GeckoFx,主要是因为我读到它的命令功能与原始 webBrowser 的工作方式非常相似(命令如 GetElementById)。
我正在尝试创建一个让我自动登录到“login.live.com”的程序。我不知道为什么,但是当它运行代码时,“密码”值输入接缝工作,但电子邮件没有。请帮我找出原因!
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 XLP_2_11_16__2_
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
//This is not the actual folder location. Part of it was suppstituded by "..." for safety reasons.
Gecko.Xpcom.Initialize(@"C:\...\bin\Debug\xulrunner");
}
private void Form1_Load(object sender, EventArgs e)
{
geckoWebBrowser1.Navigate("https://login.live.com");
}
private void button1_Click(object sender, EventArgs e)
{
//Actual email and password was substituted for safety reasons.
string email = "myemail@email.com";
string pass = "mypassword";
geckoWebBrowser1.Document.GetElementById("i0116").SetAttribute("value", email);
geckoWebBrowser1.Document.GetElementById("i0118").SetAttribute("value", pass);
geckoWebBrowser1.Navigate("javascript:void(document.forms[0].submit())");
}
private void geckoWebBrowser1_Click(object sender, EventArgs e)
{
}
private void geckoWebBrowser1_DocumentCompleted(object sender, Gecko.Events.GeckoDocumentCompletedEventArgs e)
{
}
public void Delayed(int delay, Action action)
{
Timer timer = new Timer();
timer.Interval = delay;
timer.Tick += (s, e) => {
action();
timer.Stop();
};
timer.Start();
}
}
}
这是表单设计:
如果有人知道更好的方法,请告诉我 请帮忙!!
【问题讨论】:
标签: javascript c# visual-studio-2015 geckofx