Skip to content

Commit c94944c

Browse files
committed
文本框并输入关键字
1 parent 936c2f1 commit c94944c

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

c#/web/Web.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class Web{
99
IWebDriver iebw;
1010
string url = "www.baidu.com";
1111
string btn = "su";
12+
string kw = "kw";
1213
string jsZoom = "document.body.style.zoom='1'";
1314
public Web() {
1415
iebw = new InternetExplorerDriver();
@@ -21,8 +22,6 @@ public Web() {
2122
void GetWebPage() {
2223
ExecJavaScript(jsZoom);
2324
iebw.Navigate().GoToUrl(url);
24-
IWebElement element = iebw.FindElement(By.Id(btn));
25-
ExecJavaScript(element);
2625
}
2726

2827
void ExecJavaScript(IWebElement element)
@@ -38,10 +37,27 @@ void ExecJavaScript(string jsCmd)
3837
Thread.Sleep(5000);
3938
js.ExecuteScript(jsCmd);
4039
}
40+
41+
void StartSearch()
42+
{
43+
IWebElement element = iebw.FindElement(By.Id(btn));
44+
Console.WriteLine(element.ToString());
45+
ExecJavaScript(element);
46+
}
47+
48+
void InputKeyWord()
49+
{
50+
IWebElement element = iebw.FindElement(By.Id(kw));
51+
Console.WriteLine(element.ToString());
52+
element.SendKeys("123456");
53+
}
4154
// 在属性中修改为控制台程序,才能看到输出
4255
public static void Main(string[] args) {
4356
Console.WriteLine("Main");
4457
Web wc = new Web();
4558
wc.GetWebPage();
59+
wc.InputKeyWord();
60+
wc.StartSearch();
61+
return;
4662
}
4763
}

0 commit comments

Comments
 (0)