|
@@ -426,3 +426,101 @@ func Click(page *rod.Page, x, y float64) {
|
|
|
func selectAll2(page *rod.Page) {
|
|
|
page.Keyboard.MustType(input.ControlLeft).MustType('a').MustType('a').MustType(input.ControlLeft)
|
|
|
}
|
|
|
+
|
|
|
+// 输入文字Str
|
|
|
+func InputStr(p *rod.Page, selector, inputVal string) {
|
|
|
+ err := rod.Try(func() {
|
|
|
+ e := rod.Try(func() {
|
|
|
+ p.Timeout(time.Duration(1 * float64(time.Second))).MustSearch(selector).MustSelectAllText().MustFrame().Keyboard.MustType(input.Backspace)
|
|
|
+ })
|
|
|
+ if e != nil {
|
|
|
+ logger.Info(e.Error() + "-" + selector + "-" + inputVal)
|
|
|
+ }
|
|
|
+ e = rod.Try(func() {
|
|
|
+ p.Timeout(time.Duration(1 * float64(time.Second))).MustSearch(selector).MustSelectAllText().MustInput(inputVal)
|
|
|
+ })
|
|
|
+ if e != nil {
|
|
|
+ logger.Info(strings.Split(e.Error(), "\t")[0] + "-" + selector + "-" + inputVal)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ logger.Info(err.Error() + "-" + selector + "-" + inputVal)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// 输入文字 string
|
|
|
+func InputElementXStr(p *rod.Page, xPath, inputVal string) {
|
|
|
+ elementX := MustElementX(p, xPath)
|
|
|
+ disabled := elementX.MustAttribute("disabled")
|
|
|
+ if disabled != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ readonly := elementX.MustAttribute("readonly")
|
|
|
+ if readonly != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ elementX.MustSelectAllText().MustInput(inputVal)
|
|
|
+}
|
|
|
+
|
|
|
+func WaitElementXFoTimesNil(page *rod.Page, xpath string, times int) *rod.Element {
|
|
|
+ for i := 0; i < times; i++ {
|
|
|
+ if has, el, _ := HasX(page, xpath); has && MustElementX(page, xpath).MustVisible() {
|
|
|
+ return el
|
|
|
+ }
|
|
|
+ time.Sleep(time.Second)
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+func MustElementX10(page *rod.Page, xpath string) *rod.Element {
|
|
|
+ for i := 0; i < 10; i++ {
|
|
|
+ x, _ := ElementX(page, xpath)
|
|
|
+ if x != nil {
|
|
|
+ return x
|
|
|
+ }
|
|
|
+ utils.Sleep(1)
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+func MustElementX15(page *rod.Page, xpath string) *rod.Element {
|
|
|
+ for i := 0; i < 15; i++ {
|
|
|
+ x, _ := ElementX(page, xpath)
|
|
|
+ if x != nil {
|
|
|
+ return x
|
|
|
+ }
|
|
|
+ utils.Sleep(1)
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+func MustHasXV30(page *rod.Page, xpath string) bool {
|
|
|
+ for _, element := range MustElementsX30(page, xpath) {
|
|
|
+ visible, _ := element.Visible()
|
|
|
+ if visible {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false
|
|
|
+}
|
|
|
+func MustElementsX30(page *rod.Page, xpath string) (x []*rod.Element) {
|
|
|
+ for i := 0; i < 30; i++ {
|
|
|
+ x, _ = ElementsX(page, xpath)
|
|
|
+ if len(x) != 0 {
|
|
|
+ break
|
|
|
+ }
|
|
|
+ utils.Sleep(1)
|
|
|
+ }
|
|
|
+ return x
|
|
|
+}
|
|
|
+
|
|
|
+func WaitElementXFoTimes(page *rod.Page, xpath string, times int) *rod.Element {
|
|
|
+ for i := 0; i < times; i++ {
|
|
|
+ if has, el, _ := HasX(page, xpath); has && MustElementX(page, xpath).MustVisible() {
|
|
|
+ return el
|
|
|
+ }
|
|
|
+ time.Sleep(time.Second)
|
|
|
+ }
|
|
|
+ logger.Info("页面加载失败元素未找到,请稍后再试", xpath)
|
|
|
+ panic(taxerr.NewWebStuckTitle(InfoCscsts))
|
|
|
+}
|