jason hai 1 ano
pai
achega
ebf0c7c6a6
Modificáronse 4 ficheiros con 41 adicións e 3 borrados
  1. 1 1
      common.yaml
  2. 1 1
      main.go
  3. 1 0
      record.txt
  4. 38 1
      student/student.go

+ 1 - 1
common.yaml

@@ -1,6 +1,6 @@
 videoInterval: 2
 courses:
-- "形势与政策"
+- "建筑力学"
 specialCourses:
 - "工程计量与计价实务"
 - "斜弱视技术"

+ 1 - 1
main.go

@@ -81,7 +81,7 @@ func main() {
 	for {
 		accounts, _ := student.GetAcounts("account.txt")
 		//accounts = accounts[0:1]
-		//accounts[0][0] = "2251101200217"
+		//accounts[0][0] = "2051101250176"
 		//accounts[0][1] = "Ouchn@2021"
 		//accounts[0][2] = "将"
 		fmt.Printf("accounts:%v\n", len(accounts))

+ 1 - 0
record.txt

@@ -23,3 +23,4 @@
 2151106400064 Ouchn@2021 将
 2251101200217 Ouchn@2021 将
 2251101200217 Ouchn@2021 将
+2051101250176 Ouchn@2021 将

+ 38 - 1
student/student.go

@@ -254,6 +254,30 @@ func nextPage(wd selenium.WebDriver) []selenium.WebElement {
 	return buttons
 }
 
+func tryChangePassSure(wd selenium.WebDriver) bool {
+	act, err := wd.ActiveElement()
+	if err != nil {
+		fmt.Printf("find active element\n")
+		return false
+	}
+	_, err = act.FindElement(selenium.ByXPATH, "//div[contains(text(), '请尽快修改密码')]")
+	if err != nil {
+		fmt.Printf("find active element to change pass\n")
+		return false
+	}
+	sure, err := act.FindElement(selenium.ByXPATH, "//span[text()='确定']")
+	if err != nil {
+		fmt.Printf("find active element to change pass sure\n")
+		return false
+	}
+	err = tryClick(wd, sure)
+	if err != nil {
+		fmt.Printf("find active element to click\n")
+		return false
+	}
+	return true
+}
+
 func StartOneStudentHandle(usernameText string, passwordText string, realName string) (*selenium.Service, selenium.WebDriver, error) {
 
 	var (
@@ -409,10 +433,23 @@ func StartOneStudentHandle(usernameText string, passwordText string, realName st
 	}
 	//time.Sleep(1200 *time.Second)
 	//return service, wd, errors.New("登录测试")
+
+	time.Sleep(2 * time.Second)
+	tryChangePassSure(wd)
 	// 进入学生主页
 	err = wd.WaitWithTimeout(Displayed(selenium.ByXPATH, "//a[text()='去学习']"), time.Duration(config.Conf.Timeout)*time.Second)
 	if err != nil {
-		return service, wd, errors.New(fmt.Sprintf("进入学生主页失败:%v\n", err))
+
+		if !tryChangePassSure(wd) {
+			return service, wd, errors.New(fmt.Sprintf("进入学生主页失败:%v\n", err))
+		}
+		time.Sleep(2 * time.Second)
+		err = wd.WaitWithTimeout(Displayed(selenium.ByXPATH, "//a[text()='去学习']"), time.Duration(config.Conf.Timeout)*time.Second)
+		if err != nil {
+			fmt.Printf("find active element to find page\n")
+			return service, wd, errors.New(fmt.Sprintf("进入学生主页失败:%v\n", err))
+		}
+
 	}
 	fmt.Printf("进入学生主页\n")