我正在尝试登录网站,似乎无法运行它,即使在我尝试单击提交中的提交时,也无法通过当前代码运行它并使其与当前代码保持一致我自己的网络浏览器。
我可以将其与注释掉的代码一起使用,但是Web浏览器必须保持打开状态,而我希望将其隐藏起来。
理想情况下,我想使用网络浏览器,因为到目前为止,我已经使用网络浏览器完成了所有操作,但是如果不能,我可以尝试硒,并且我想知道为什么它不起作用。 / p>
如果您具有正确的库,此代码将完全重现问题。如果在MainSite
方法的末尾放置一个中断,它将在发生问题的位置停止。如果您随后尝试单击“登录”按钮,则不会发生任何事情,但是如果您退格一个字符,则可以再次单击该按钮,这将告诉您密码输入错误。
希望这可以继续进行下去。
using System.Windows.Forms;
using SHDocVw;
using MSHTML;
using System.Threading;
namespace ShiftCodes
{
public partial class Form1 : Form
{
public Form1()
{
//InitializeComponent();
MainSite();
}
void MainSite()
{
InternetExplorer ie = new InternetExplorer();
string loginsite = "https://borderlands.com/en-US/vip-codes/";
SHDocVw.WebBrowser wb = (SHDocVw.WebBrowser)ie;
HTMLDocument document = new HTMLDocument();
wb.Visible = true;
wb.Navigate(loginsite);
while (wb.Busy) { Thread.Sleep(1000); }
document = ((HTMLDocument)wb.Document);
IHTMLElementCollection links = document.getElementsByTagName("A");
foreach (IHTMLElement link in links)
{
var sss = link.innerText;
if (link.innerText != null)
{
if (link.innerText.Contains("Login"))
link.click();
}
}
while (wb.Busy) { Thread.Sleep(1000); }
links = document.getElementsByTagName("A");
foreach (IHTMLElement link in links)
{
var sss = link.innerText;
if (link.innerText != null)
{
if (link.innerText.Contains("Continue"))
link.click();
}
}
while (wb.Busy) { Thread.Sleep(1000); }
foreach (HTMLInputElement element in document.getElementsByTagName("input"))
{
if (element.name == "username")
{
element.setAttribute("value", "email@gmail.com");
//element.focus();
//SendKeys.SendWait("email@gmail.com");
//Thread.Sleep(100);
}
if (element.name == "password")
{
element.value = "Password";
//element.focus();
//SendKeys.SendWait("Password");
//Thread.Sleep(100);
}
}
foreach (HTMLInputElement element in document.getElementsByTagName("button"))
{
if (element.innerText.Contains("Sign In"))
{
element.click();
}
}
}
}
}