定位及处理Web页面toast弹框

what?
在Selenium项目中,对页面做出修改之后,弹出消息提示框,也就是toast。
toast,Web页面的消息提示框,动画出现,弹出一段时间后自动消失。e.g.

why?
在实际项目中,用例的失败与否可以借助toast的属性来断言,所以需要定位toast,并且获取其属性。

how?
1.定位toast位置
解决办法如下:

2.获取toast属性
介绍selenium.webdriver中get_attribute的用法
"Gets the given attribute or property of the element"源码的备注
get_attribute不能以webdriver类对象引用它,要用页面位置。

e.g:

toast = driver.find_element_by_xpath('/html/body/div[3]/div')
text = toast.get_attribute('textContent')

textContent是标签的HTML DOM 属性,代表文本内容,类似的还有 className,nodeValue。
注:Internet Explorer 8 以及更早的版本不支持此属性

猜你喜欢

转载自www.cnblogs.com/hill233/p/12221675.html