我已经尝试了很多方法,但我无法使它正常工作 我想自动登录该网站 这是网站http://www.action-manga.com/account/login 我无法发送用户名和密码,但是我无法单击登录按钮
我尝试过WebBrowser和Selenium(firefox和chrome)
ChromeDriver cd = new ChromeDriver();
cd.Url = url;
cd.Navigate();
IWebElement we = cd.FindElementByName("user-email");
we.SendKeys("****");
we = cd.FindElementByName("user-password");
we.SendKeys("****");
Thread.Sleep(3000);
we = cd.FindElementByClassName("frmSBM button");
we.Click();
//these also
//we = cd.FindElementByName("ws_login");
//we.Click();
//((IJavaScriptExecutor)(cd)).ExecuteScript("arguments[0].click();", cd.FindElement(By.Name("ws_login")));
//((IJavaScriptExecutor)cd).ExecuteScript("arguments[0].trigger('click');", cd.FindElement(By.ClassName("frmSBM button")));
和WebBrowser
public partial class MainWindow : Window
{
WebBrowser wb = new WebBrowser();
public MainWindow()
{
InitializeComponent();
wb.ScriptErrorsSuppressed = true;
wb.Navigate(url);
wb.DocumentCompleted += Wb_DocumentCompleted;
}
private void Wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (e.Url.AbsolutePath != (sender as WebBrowser).Url.AbsolutePath)
return;
if (!is_sec_page)
{
//Set username and password strings
string usernameString = "****";
string passwordString = "****";
//Input in to username field
var x = wb.Document.All.GetElementsByName("user-email");
x[0].InnerText = usernameString;
//Input in to password fields
var y = wb.Document.All.GetElementsByName("user-password");
y[0].InnerText = passwordString;
//Click the login button
var s = wb.Document.All.GetElementsByName("ws_login");
s[0].InvokeMember("click");
is_sec_page = true;
}
else
{
//intract with sec page elements with theire ids and so on
}
}
}
和许多其他方式, 这是标记
<div class="form-group frmINP buttons"> <input type="hidden" name="ws_login" value="uLogOct"> <button class="frmSBM button">دخول</button> </div>
答案 0 :(得分:3)
您需要找到表格ID并提交
更改了密码
we = cd.FindElementByClassName("frmSBM button");
we.Click();
正确
we = cd.FindElementById("loginform");
we.Submit();
答案 1 :(得分:0)
尝试一下:
call
步骤:
答案 2 :(得分:-1)
此
we = cd.FindElementByClassName("frmSBM button");
应该是
we = ((FindsByClassName)cd).FindElementByClassName("frmSBM button");