修复点击事件仍抛出ElementClickInterceptedException异常导致点击停止的问题

This commit is contained in:
彭宇琦 2020-05-12 15:15:33 +08:00
parent df6328c302
commit c571125f9a
1 changed files with 18 additions and 10 deletions

View File

@ -1,5 +1,6 @@
package pres.auxiliary.work.selenium.event;
import org.openqa.selenium.ElementClickInterceptedException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
@ -7,19 +8,15 @@ import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
/**
* <p>
* <b>文件名</b>ClickEvent.java
* </p>
* <p>
* <b>用途</b>定义了对控件进行点击操作相关的方法可通过该类对页面进行基本的点击操作
* </p>
* <p>
* <b>编码时间</b>2019年8月29日下午3:24:34
* <p><b>文件名</b>ClickEvent.java</p>
* <p><b>用途</b>
* 定义了对控件进行点击操作相关的方法可通过该类对页面进行基本的点击操作
* </p>
* <p><b>编码时间</b>2019年8月29日下午3:24:34</p>
* <p><b>修改时间</b>2020年5月10日 下午3:42:36</p>
*
* @author 彭宇琦
* @version Ver1.0
* @version Ver2.0
* @since JDK 12
*
*/
@ -42,7 +39,18 @@ public class ClickEvent extends AbstractEvent {
//元素高亮
elementHight(element);
//在等待时间内判断元素是否可以点击若可以点击元素则进行点击事件
new WebDriverWait(driver, waitTime, 200).until(ExpectedConditions.elementToBeClickable(element)).click();
new WebDriverWait(driver, waitTime, 200).
until(ExpectedConditions.elementToBeClickable(element));
new WebDriverWait(driver, waitTime, 200).
until((driver) -> {
try {
element.click();
} catch (ElementClickInterceptedException e) {
return false;
}
return true;
});
//记录操作内容
result = "";