差異處
這裏顯示兩個版本的差異處。
rf:rf:howtoassertmultipletextnode [2016/07/08 11:33] tony [How to?] |
rf:rf:howtoassertmultipletextnode [2023/06/25 09:48] |
||
---|---|---|---|
行 1: | 行 1: | ||
- | {{tag>RobotFramework}} | ||
- | ====== How to assert multiple text node? ====== | ||
- | ===== Problem ===== | ||
- | 傳統的網頁資料更新,都是透過刷新整頁方式;隨著javascript的普及化,進步到針對dom node刷新。而資料型態如果為遞增的方式,像jenkins build info或是動作執行過程,很可能為了效能不針對整個node刷新,而採用append的方式。透過瀏覽器所提供的Element檢測器,會看到如下圖情況:\\ | ||
- | {{:rf:rf:rf_pre_node_with_mutiple_text.png|}}\\ | ||
- | \\ | ||
- | 一個pre code底下包含了三個text node,當在Selenium IDE與Chrome Developer Tools中使用以下xpath,是無法找到任何批配的節點:\\ | ||
- | {{:rf:rf:rf_pre_node_with_mutiple_text_seleniumide.png|}}\\ | ||
- | \\ | ||
- | 本篇文章主要告訴你,如果某個節點資料是動態插入的,該如何透過selenium去做assert。 | ||
- | ===== How to? ===== | ||
- | ===== 測試網頁 ===== | ||
- | <code html> | ||
- | <!DOCTYPE html> | ||
- | <html> | ||
- | <head> | ||
- | <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> | ||
- | <script> | ||
- | $(document).ready(function(){ | ||
- | $("#gg").append('g1'); | ||
- | $("#gg").append('g2'); | ||
- | $("#gg").append('g3'); | ||
- | }); | ||
- | </script> | ||
- | </head> | ||
- | <body> | ||
- | |||
- | <pre id='gg'></pre> | ||
- | |||
- | </body> | ||
- | </html> | ||
- | </code> | ||
- | ===== Reference ===== | ||
- | * [[http://stackoverflow.com/questions/5033955/xpath-select-text-node|Stackoverflow - Xpath to select text node]] | ||
- | * [[http://stackoverflow.com/questions/3655549/xpath-containstext-some-string-doesnt-work-when-used-with-node-with-more|Stackoverflow - XPath contains(text(),'some string') doesn't work when used with node with more than one Text subnode]] | ||
- | |||
- | ===== ===== | ||
- | ---- | ||
- | \\ | ||
- | ~~DISQUS~~ |