使用Selenium Chrome C#填写密码

问题描述 投票:0回答:2

今天登录页面被更改https://fastinvest.com/de/investor/login,我无法用selenium和chrome webdriver填写密码。

我通常使用XPath,但表单字段不会被填写。我也试图执行一个JavaScript,但我无法做到。

如果你能帮助我找出如何输入密码,那将是非常好的。

            browser = new ChromeDriver("Chrome-Path", options);
            browser.Url = "https://fastinvest.com/de/investor/login";
            browser.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(60);

            IWebElement elem = browser.FindElement(By.CssSelector("input#loginEmail.form-control"));
            elem.SendKeys("[email protected]");
            elem.FindElement(By.CssSelector("input#loginPassword.form-control")).SendKeys("[email protected]");
c# google-chrome selenium
2个回答
0
投票

按名称查找元素:

elem.FindElement(By.Name("password")).SendKeys("[email protected]");

这也可以:

elem.FindElement(By.Id("loginPassword")).SendKeys("[email protected]");

0
投票

您不需要浏览器控件来向服务器发布用户名/密码。在你的情况下,它可以是:

string url = "https://fastinvest.com/de/auth/login";
using (var client = new HttpClient())
{
    Dictionary<string, string> values = new Dictionary<string, string>()
    {
        { "_token","MNpOE4CLgMAelhtwNmG5dhxt1JCUCZsbj9CXnwQT" },
        {"email","[email protected]" },
        {"password","12345" }
    };

    var content = new FormUrlEncodedContent(values);
    var response = await client.PostAsync(url, content);
    var html = await response.Content.ReadAsStringAsync();
}

PS:查看您网站的html内容并检查FORM元素

© www.soinside.com 2019 - 2024. All rights reserved.