3737import org .springframework .stereotype .Component ;
3838import org .suren .autotest .web .framework .core .ElementSearchStrategy ;
3939import org .suren .autotest .web .framework .core .action .ClickAble ;
40+ import org .suren .autotest .web .framework .core .ui .AbstractElement ;
4041import org .suren .autotest .web .framework .core .ui .Element ;
4142import org .suren .autotest .web .framework .core .ui .FileUpload ;
4243import org .suren .autotest .web .framework .selenium .SeleniumEngine ;
@@ -55,7 +56,8 @@ public class SeleniumClick implements ClickAble
5556
5657 /** 失败后重试的最大次数 */
5758 private int maxRetry = 3 ;
58- private int errorTimes = 0 ;
59+
60+ private static final String ERR_TIMES = "CLICK_ERR_TIMES" ;
5961
6062 @ Autowired
6163 private SeleniumEngine engine ;
@@ -65,10 +67,19 @@ public class SeleniumClick implements ClickAble
6567 @ Override
6668 public void click (Element ele )
6769 {
68- if (errorTimes >= maxRetry )
70+ int errorTimes = 0 ;
71+
72+ if (ele instanceof AbstractElement )
6973 {
70- errorTimes = 0 ;
71- return ;
74+ Object errObj = ((AbstractElement ) ele ).getData (ERR_TIMES );
75+ if (errObj instanceof Integer )
76+ {
77+ errorTimes = (Integer ) errObj ;
78+ if (errorTimes >= maxRetry )
79+ {
80+ return ;
81+ }
82+ }
7283 }
7384
7485 if (errorTimes > 0 )
@@ -116,13 +127,14 @@ public void click(Element ele)
116127 driver .switchTo ().window (name );
117128 }
118129 }
119-
120- errorTimes = 0 ;
121130 }
122131 catch (WebDriverException e )
123132 {
124133 logger .error (String .format ("元素[%s]点击操作发生错误。" , webEle ), e );
125- errorTimes ++;
134+ if (ele instanceof AbstractElement )
135+ {
136+ ((AbstractElement ) ele ).putData (ERR_TIMES , ++errorTimes );
137+ }
126138
127139 //如果由于目标元素不在可见区域导致的异常,尝试滚动屏幕
128140 if (e .getMessage ().contains ("is not clickable at point" ))
0 commit comments