Skip to content

Commit cab9758

Browse files
committed
TsDownload
1 parent c94944c commit cab9758

File tree

2 files changed

+54
-6
lines changed

2 files changed

+54
-6
lines changed

c#/web/TsDownload.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using System.Threading;
3+
using OpenQA.Selenium;
4+
using OpenQA.Selenium.IE;
5+
using OpenQA.Selenium.Chrome;
6+
using OpenQA.Selenium.Support;
7+
8+
class TsDownload {
9+
IWebDriver iebw;
10+
string url = "https://www.ztbw.net/guocanju/gdjzj/1-3.html";
11+
string jsZoom = "document.body.style.zoom='1'";
12+
public TsDownload()
13+
{
14+
iebw = new InternetExplorerDriver();
15+
// iebw = new ChromeDriver();
16+
}
17+
~TsDownload()
18+
{
19+
iebw.Close();
20+
}
21+
public void GetWebPage()
22+
{
23+
ExecJavaScript(jsZoom);
24+
iebw.Navigate().GoToUrl(url);
25+
}
26+
27+
void ExecJavaScript(IWebElement element)
28+
{
29+
IJavaScriptExecutor js = (IJavaScriptExecutor)iebw;
30+
Thread.Sleep(5000);
31+
js.ExecuteScript("arguments[0].click();", element);
32+
}
33+
34+
void ExecJavaScript(string jsCmd)
35+
{
36+
IJavaScriptExecutor js = (IJavaScriptExecutor)iebw;
37+
Thread.Sleep(5000);
38+
js.ExecuteScript(jsCmd);
39+
}
40+
41+
public int FindElementById(string kw)
42+
{
43+
IWebElement element = iebw.FindElement(By.Id(kw));
44+
Console.WriteLine(element.ToString());
45+
element.SendKeys("123456");
46+
return 0;
47+
}
48+
}

c#/web/Web.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public Web() {
1919
{
2020
iebw.Close();
2121
}
22-
void GetWebPage() {
22+
public void GetWebPage() {
2323
ExecJavaScript(jsZoom);
2424
iebw.Navigate().GoToUrl(url);
2525
}
@@ -38,14 +38,14 @@ void ExecJavaScript(string jsCmd)
3838
js.ExecuteScript(jsCmd);
3939
}
4040

41-
void StartSearch()
41+
public void StartSearch()
4242
{
4343
IWebElement element = iebw.FindElement(By.Id(btn));
4444
Console.WriteLine(element.ToString());
4545
ExecJavaScript(element);
4646
}
4747

48-
void InputKeyWord()
48+
public void InputKeyWord()
4949
{
5050
IWebElement element = iebw.FindElement(By.Id(kw));
5151
Console.WriteLine(element.ToString());
@@ -54,10 +54,10 @@ void InputKeyWord()
5454
// 在属性中修改为控制台程序,才能看到输出
5555
public static void Main(string[] args) {
5656
Console.WriteLine("Main");
57-
Web wc = new Web();
57+
// Web wc = new Web();
58+
TsDownload wc = new TsDownload();
5859
wc.GetWebPage();
59-
wc.InputKeyWord();
60-
wc.StartSearch();
60+
wc.FindElementById("lelevideo");
6161
return;
6262
}
6363
}

0 commit comments

Comments
 (0)