public abstract class FindElement extends Object
文件名:AbstractElement.java
用途:
对辅助化测试工具selenium的获取元素代码进行的二次封装,通过类中提供的方法以及配合相应存储元素的 xml文件,以更简便的方式对页面元素进行获取,减少编程时的代码量。
编码时间:2020年4月25日 下午4:18:37
修改时间:2021年4月10日下午2:53:33
Modifier and Type | Field and Description |
---|---|
protected ExceptionAction |
action
用于当元素获取失败时执行的方法
|
protected AbstractBrower |
brower
用于存储浏览器对象
|
protected ElementData |
elementData
用于存储元素信息
|
protected List<org.openqa.selenium.WebElement> |
elementList
存储通过信息获取到的页面元素对象
|
protected boolean |
isAutoSwitchIframe
控制是否自动切换窗体,由于通过Event类调用时会构造另一个事件类
|
protected static AbstractLocation |
read
存储元素的定位方式读取类对象,由于多个子类之间需要互通,故此处标记为static
|
Constructor and Description |
---|
FindElement(AbstractBrower brower)
通过元素信息类对象(
ElementData )构造对象 |
Modifier and Type | Method and Description |
---|---|
protected void |
autoSwitchContext(ElementData elementData)
该方法用于自动切换app元素的上下文
|
protected void |
autoSwitchFrame(List<String> iframeNameList)
用于根据元素的窗体层级关系列表,对元素的窗体进行切换,并存储当前切换的窗体
|
void |
clearAction()
用于清除元素查找失败时执行的方法
|
protected List<org.openqa.selenium.WebElement> |
findElement(List<ElementLocationInfo> locationList,
long waitTime)
根据传入的定位方式枚举,以及定位内容,在页面查找 元素,返回查到的元素列表,若查不到元素,则返回空列表
|
protected org.openqa.selenium.By |
getBy(String value,
ByType byType)
根据元素的参数,返回元素的By对象
|
ElementData |
getElementData()
返回当前进行搜索的元素信息类(
ElementData )对象 |
protected List<org.openqa.selenium.WebElement> |
recognitionElement(ElementData elementData)
用于根据元素信息,在页面上对数据进行查找
|
void |
setAction(ExceptionAction action)
设置元素查找失败时需要执行的方法
|
void |
setAutoSwitchIframe(boolean isAutoSwitchIframe)
设置是否自动切换窗体
|
void |
setReadMode(AbstractLocation read,
boolean isBreakRootFrame)
用于设置元素定位方式文件读取类对象
|
void |
setWaitTime(long waitTime)
用于设置元素的默认等待时间
|
void |
switchAppNativeContext()
用于切换到app的原生上下文中
|
void |
switchFrame(ElementData iframeElementData)
该方法用于根据iframe_id来切换窗体
|
void |
switchParentFrame(int count)
该方法用于将窗体切换到上一层(父层)。若当前层只有一层,则调用方法后切回顶层; 若当前层为最顶层时,则该方法将使用无效
|
void |
switchRootFrame()
该方法用于将窗体切回顶层,当本身是在最顶层时,则该方法将使用无效
|
void |
switchWebViewContext(String context)
用于根据写入到元素信息中的WebView上下文,对WebView上下文进行切换
|
protected int |
toElementIndex(int length,
int index,
boolean firstEmpty)
由于方法允许传入负数和特殊数字0为下标,并且下标的序号由1开始,故可通过该方法对下标的含义进行转义,得到java能识别的下标
|
protected List<org.openqa.selenium.WebElement> elementList
protected ElementData elementData
protected static AbstractLocation read
protected AbstractBrower brower
protected ExceptionAction action
protected boolean isAutoSwitchIframe
public FindElement(AbstractBrower brower)
ElementData
)构造对象brower
- AbstractBrower
类对象public void setAction(ExceptionAction action)
action
- 执行方法public void clearAction()
public void setWaitTime(long waitTime)
waitTime
- 元素的默认等待时间public void setAutoSwitchIframe(boolean isAutoSwitchIframe)
isAutoSwitchIframe
- 是否自动切换窗体public void setReadMode(AbstractLocation read, boolean isBreakRootFrame)
isBreakRootFrame参数表示是否将所有的元素切回到顶层,对于web元素而言,则是将iframe切回到顶层;对于app元素 而言,则是将上下文切换至原生层
read
- 元素定位方式文件读取类对象isBreakRootFrame
- 是否需要将窗体切回到顶层public ElementData getElementData()
ElementData
)对象public void switchRootFrame()
public void switchParentFrame(int count)
count
- 需要切换父层的次数public void switchFrame(ElementData iframeElementData)
iframeElementData
- 窗体的信息public void switchAppNativeContext()
注意:该方法对web端元素无效
public void switchWebViewContext(String context)
注意:该方法对web端元素无效,若元素信息中元素上下文属性为空,则按照默认的名称进行切换
context
- 上下文内容protected void autoSwitchContext(ElementData elementData)
elementData
- ElementData
类对象protected void autoSwitchFrame(List<String> iframeNameList)
iframeNameList
- 元素所有窗体名称集合protected org.openqa.selenium.By getBy(String value, ByType byType)
protected List<org.openqa.selenium.WebElement> recognitionElement(ElementData elementData)
elementData
- ElementData
类对象WebElement
类对象List
集合protected List<org.openqa.selenium.WebElement> findElement(List<ElementLocationInfo> locationList, long waitTime)
locationList
- 元素定位信息类ElementLocationInfo
对象waitTime
- 元素查找超时时间WebElement
类对象List
集合protected int toElementIndex(int length, int index, boolean firstEmpty)
length
- 元素的个数index
- 传入的下标org.openqa.selenium.NoSuchElementException
- 当元素无法查找到时抛出的异常Copyright © 2024. All rights reserved.