在C#中使用Selenium Webdriver,如何选择要写入的文本框,然后在其中写入? [英] Using Selenium Webdriver in C#, how do I select a text box to write in, then write in it?

查看:358
本文介绍了在C#中使用Selenium Webdriver,如何选择要写入的文本框,然后在其中写入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Have a script to go to the website. Now I want to login and proceed to next screen. Can't find code on how to go to 'username:' text box, then 'password:' text box.

推荐答案

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

You will need to give us some HTML of the page, but given a password textbox like this:

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

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

I'd find it using Selenium's WebDriver like so:

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

然后我将像这样写入"到其中:

I would then 'write' into it like so:

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

我将看一看Selenium Web驱动程序文档,并在阅读全部内容后提出任何问题:

I would take a look at the Selenium Web Driver documentation, and ask any questions after you've read through it all:

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

这篇关于在C#中使用Selenium Webdriver,如何选择要写入的文本框,然后在其中写入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆