Browse Source

InputElementX

1 2 weeks ago
parent
commit
cc173b5609
2 changed files with 26 additions and 1 deletions
  1. 7 0
      common/converter.go
  2. 19 1
      common/rod_utils.go

+ 7 - 0
common/converter.go

@@ -284,3 +284,10 @@ func FormatFloat(num float64, decimal int) string {
 	// 再除回去,小数点后无效的0也就不存在了
 	return strconv.FormatFloat(math.Trunc(num*d)/d, 'f', -1, 64)
 }
+
+func DecimalDivSS(v1 string, v2 string) float64 {
+	v1 = AmountFormat2str(v1)
+	v2 = AmountFormat2str(v2)
+	r := DecimalDivFF(StrToFloat(v1), StrToFloat(v2))
+	return r
+}

+ 19 - 1
common/rod_utils.go

@@ -612,9 +612,27 @@ func HijackReq(page *rod.Page, uri, xPath string) []byte {
 	MustElementX(page, xPath).MustClick()
 	data, err := GetHijackResp(ch, 10)
 	if err != nil {
-		zaplog.LoggerS.Info(string(data))
 		panic(taxerr.NewWebStuckTitle(false))
 	}
 	_ = r.Stop()
 	return data
 }
+
+// 输入文字 float
+func InputElementX(p *rod.Page, xPath, inputVal string) {
+	disabled := MustElementX(p, xPath).MustAttribute("disabled")
+	if disabled != nil {
+		return
+	}
+	readonly := MustElementX(p, xPath).MustAttribute("readonly")
+	if readonly != nil {
+		return
+	}
+	float := StrToFloat(inputVal)
+	if float == 0 {
+		inputVal = ""
+	} else {
+		inputVal = FloatToStr(float)
+	}
+	MustElementX(p, xPath).MustSelectAllText().MustInput(inputVal)
+}