定位及處理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 以及更早的版本不支持此屬性


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM