调整等待事件类结构,修改元素重新拉取方法

This commit is contained in:
彭宇琦 2020-12-09 07:57:51 +08:00
parent 331ec824c0
commit 730a173392
5 changed files with 16 additions and 13 deletions

View File

@ -257,6 +257,11 @@ public abstract class AbstractBy {
* @return {@link WebElement}类对象{@link List}集合
*/
protected List<WebElement> recognitionElement(ElementData elementData) {
//判断是否需要自动切换窗体若需要则对元素窗体进行切换
if (isAutoSwitchIframe) {
autoSwitchFrame(elementData.getIframeNameList());
}
//获取元素的定位类型及定位内容
ArrayList<ByType> elementByTypeList = elementData.getByTypeList();
ArrayList<String> elementValueList = elementData.getValueList();

View File

@ -40,11 +40,6 @@ public class CommonBy extends AbstractBy {
elementData = new ElementData(elementName, read);
elementData.addLinkWord(linkKeys);
//判断是否需要自动切换窗体若需要则对元素窗体进行切换
if (isAutoSwitchIframe) {
autoSwitchFrame(elementData.getIframeNameList());
}
//获取元素数据在页面上对应的一组元素若无法查到元素则记录elementList为null
try {
elementList = recognitionElement(elementData);

View File

@ -1,6 +1,9 @@
package pres.auxiliary.work.selenium.element;
import java.util.ArrayList;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.WebElement;
/**
@ -94,10 +97,15 @@ public class Element {
* 重新根据元素信息在页面查找元素
*/
public int againFindElement() {
//重新拉取元素
abstractBy.elementList = abstractBy.recognitionElement(elementData);
//切换当前读取的元素信息
abstractBy.elementData = elementData;
//重新拉取元素数据在页面上对应的一组元素若无法查到元素则记录elementList为null
try {
abstractBy.elementList = abstractBy.recognitionElement(elementData);
} catch (TimeoutException e) {
abstractBy.elementList = new ArrayList<>();
}
return abstractBy.elementList.size();
}

View File

@ -64,11 +64,6 @@ public abstract class MultiBy<T extends MultiBy<T>> extends AbstractBy {
elementData = new ElementData(elementName, read);
elementData.addLinkWord(linkKeys);
//判断是否需要自动切换窗体若需要则对元素窗体进行切换
if (isAutoSwitchIframe) {
autoSwitchFrame(elementData.getIframeNameList());
}
//获取元素数据在页面上对应的一组元素若无法查到元素则记录elementList为null
try {
elementList = recognitionElement(elementData);

View File

@ -68,7 +68,7 @@ public class WaitEvent extends AbstractEvent{
//调用isDisplayed()方法判断元素是否存在
try {
return !element.getWebElement().isDisplayed();
} catch (NoSuchElementException e) {
} catch (NoSuchElementException | TimeoutException e) {
//若在调用获取页面元素时抛出NoSuchElementException异常则说明元素本身不存在则直接返回true
return true;
} catch (StaleElementReferenceException e) {