what?

在Selenium项目中,对页面做出修改之后,弹出消息提示框,也就是toast。

toast,Web页面的消息提示框,动画出现,弹出一段时间后自动消失。e.g.

20200121164259795555.gif

why?

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

how?

1.定位toast位置

解决办法如下:

20200121164259951795.png

20200121164300137330.png

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 以及更早的版本不支持此属性

原文:https://www.cnblogs.com/hill233/p/12221675.html

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐