From 730a1733923e1e182548adc189ce6eba12bb84a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BD=AD=E5=AE=87=E7=90=A6?= <465645774@qq.com> Date: Wed, 9 Dec 2020 07:57:51 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=AD=89=E5=BE=85=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E7=B1=BB=E7=BB=93=E6=9E=84=EF=BC=8C=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=85=83=E7=B4=A0=E9=87=8D=E6=96=B0=E6=8B=89=E5=8F=96=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auxiliary/work/selenium/element/AbstractBy.java | 5 +++++ .../auxiliary/work/selenium/element/CommonBy.java | 5 ----- .../auxiliary/work/selenium/element/Element.java | 12 ++++++++++-- .../auxiliary/work/selenium/element/MultiBy.java | 5 ----- .../auxiliary/work/selenium/event/WaitEvent.java | 2 +- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/main/java/pres/auxiliary/work/selenium/element/AbstractBy.java b/src/main/java/pres/auxiliary/work/selenium/element/AbstractBy.java index dd2aaaf..c5fd0af 100644 --- a/src/main/java/pres/auxiliary/work/selenium/element/AbstractBy.java +++ b/src/main/java/pres/auxiliary/work/selenium/element/AbstractBy.java @@ -257,6 +257,11 @@ public abstract class AbstractBy { * @return {@link WebElement}类对象{@link List}集合 */ protected List recognitionElement(ElementData elementData) { + //判断是否需要自动切换窗体,若需要,则对元素窗体进行切换 + if (isAutoSwitchIframe) { + autoSwitchFrame(elementData.getIframeNameList()); + } + //获取元素的定位类型及定位内容 ArrayList elementByTypeList = elementData.getByTypeList(); ArrayList elementValueList = elementData.getValueList(); diff --git a/src/main/java/pres/auxiliary/work/selenium/element/CommonBy.java b/src/main/java/pres/auxiliary/work/selenium/element/CommonBy.java index 0d2d649..465dde2 100644 --- a/src/main/java/pres/auxiliary/work/selenium/element/CommonBy.java +++ b/src/main/java/pres/auxiliary/work/selenium/element/CommonBy.java @@ -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); diff --git a/src/main/java/pres/auxiliary/work/selenium/element/Element.java b/src/main/java/pres/auxiliary/work/selenium/element/Element.java index 65a509a..a9ec7ca 100644 --- a/src/main/java/pres/auxiliary/work/selenium/element/Element.java +++ b/src/main/java/pres/auxiliary/work/selenium/element/Element.java @@ -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(); } diff --git a/src/main/java/pres/auxiliary/work/selenium/element/MultiBy.java b/src/main/java/pres/auxiliary/work/selenium/element/MultiBy.java index 11ecb55..129c261 100644 --- a/src/main/java/pres/auxiliary/work/selenium/element/MultiBy.java +++ b/src/main/java/pres/auxiliary/work/selenium/element/MultiBy.java @@ -64,11 +64,6 @@ public abstract class MultiBy> extends AbstractBy { elementData = new ElementData(elementName, read); elementData.addLinkWord(linkKeys); - //判断是否需要自动切换窗体,若需要,则对元素窗体进行切换 - if (isAutoSwitchIframe) { - autoSwitchFrame(elementData.getIframeNameList()); - } - //获取元素数据在页面上对应的一组元素,若无法查到元素,则记录elementList为null try { elementList = recognitionElement(elementData); diff --git a/src/main/java/pres/auxiliary/work/selenium/event/WaitEvent.java b/src/main/java/pres/auxiliary/work/selenium/event/WaitEvent.java index b2039de..429f46f 100644 --- a/src/main/java/pres/auxiliary/work/selenium/event/WaitEvent.java +++ b/src/main/java/pres/auxiliary/work/selenium/event/WaitEvent.java @@ -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) {