seldom icon indicating copy to clipboard operation
seldom copied to clipboard

selenium中的显示等待在seldom中如何调用?如:判断某个元素消失

Open jingyuezijing opened this issue 4 years ago • 4 comments

image 如下,selenium中的等待一个元素消失的方法,在seldom有接口吗? ui.WebDriverWait(driver, timeout).until_not(EC.visibility_of_element_located((By.XPATH, locator)))

jingyuezijing avatar May 19 '21 03:05 jingyuezijing

等待元素可见,seldom 默认会判断元素是否可见,根据 timeout 超时时间。

seldom.main(timeout=10)

等待元素消失,比如弹提示框之类,一定有固定的消失时间,直接 休眠即可。

self.sleep(10)

如果不知道一个元素存在还是消失,可以获取元素进行判断。

elem = get_elements(xpath="//div")

在seldom 中,不需要像你上面那样 等待元素显示或隐藏。

defnngj avatar May 28 '21 09:05 defnngj

if elem.isdisplay():

步骤1 else:

步骤2

不确定某一个元素是否存在,所以用if判断下,若if里的elem找不到。则到步骤2时,元素都获取不到了。是什么问题?

jingyuezijing avatar Jun 30 '21 10:06 jingyuezijing

希望作者能够提供或者封装下显示等待方法,当用例过多或者需要等待的用例过多,添加太多sleep影响运行时间较大,且seldom.main中有时候并没有在等待,比如应为操作过快提示stale element reference: element is not attached to the page document。必须强制等待

sobbingchild avatar Jan 28 '22 06:01 sobbingchild

在webdriver.py文件中新增了该方法,现在在项目中可以稳定运行(节省了三分之一的时间,不会再死等了。。。),具体可参考如下图,希望作者可以考虑内置该方法 image 新引用的模块 image 调用该方法 image

sobbingchild avatar Jun 15 '22 09:06 sobbingchild