提交 8f620567 authored 作者: 黄承天's avatar 黄承天

[feature]

优化等待元素机制
上级 6b50f3c1
...@@ -15,6 +15,7 @@ import lombok.extern.slf4j.Slf4j; ...@@ -15,6 +15,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.util.Strings; import org.apache.logging.log4j.util.Strings;
import org.openqa.selenium.*; import org.openqa.selenium.*;
import org.openqa.selenium.interactions.Actions; import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select; import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait; import org.openqa.selenium.support.ui.WebDriverWait;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -380,7 +381,7 @@ public class SeleniumExecutor { ...@@ -380,7 +381,7 @@ public class SeleniumExecutor {
element = getElement(target, targets); element = getElement(target, targets);
costTime = System.currentTimeMillis() - stepStartTime; costTime = System.currentTimeMillis() - stepStartTime;
if (nonNull(element)) { if (nonNull(element)) {
new Actions(driver).moveToElement(element,0,0).perform(); new Actions(driver).moveToElement(element, 0, 0).perform();
success = true; success = true;
} else { } else {
message = "无法定位该元素"; message = "无法定位该元素";
...@@ -479,7 +480,10 @@ public class SeleniumExecutor { ...@@ -479,7 +480,10 @@ public class SeleniumExecutor {
private void waitForELement(String target, List<List<String>> targets) { private void waitForELement(String target, List<List<String>> targets) {
try { try {
new WebDriverWait(driver, 3).until(webDriver -> nonNull(getElement(target, targets))); new WebDriverWait(driver, 3).until(webDriver -> {
WebElement element = getElement(target, targets);
return nonNull(element) && !ExpectedConditions.stalenessOf(element).apply(driver);
});
} catch (Exception ignored) { } catch (Exception ignored) {
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论