7

有一个脚本可以访问该网站。现在我想登录并进入下一个屏幕。找不到有关如何转到“用户名:”文本框和“密码:”文本框的代码。

4

4 回答 4

24

您将需要给我们一些页面的 HTML,但给定一个密码文本框,如下所示:

<input type="password" id="passwordTextBox">

我会像这样使用 Selenium 的 WebDriver 找到它:

IWebDriver firefoxDriver = new FirefoxDriver();
IWebElement passwordTextBox = firefoxDriver.FindElement(By.Id("passwordTextBox"));

然后我会像这样“写入”它:

passwordTextBox.Clear();
passwordTextBox.SendKeys("password");

我会看一下 Selenium Web Driver 文档,并在您通读所有内容后提出任何问题:

http://seleniumhq.org/docs/03_webdriver.html

于 2012-05-11T22:23:34.280 回答
0
//Textbox  id is "username"
IWebDriver driver = new ChromeDriver();    
string url = "https://www.google.com";
IWebElement textBox;
driver.Navigate().GoToUrl(url);
textBox = driver.FindElement(By.Name("username"));
textBox.SendKeys("Test text");
于 2019-01-14T14:03:15.537 回答
0
driver.FindElement(selectBy(controlToFind, search)).Click();

只需要使用此代码。

  • driver= 你的 selenium 网络驱动程序
  • SelectBy(controlToFind)= 这是您的控件、xpath 代码、CSS 选择器或类。
  • .Click()= 表示要执行的动作,可以使用.click(), .SendKeys(), wait()...
于 2019-04-19T18:11:52.573 回答
-2

在用户名和密码文本框中键入值。试试下面

driver.FindElement(By.Id("\\UserName Text Box ID\\").SendKeys("UserName Text");

driver.FindElement(By.Id("\\Password Text box ID\\").SendKeys("Password Text");
于 2015-04-30T10:00:18.087 回答