开发者

Selenium web test: get a list of links names from html

开发者 https://www.devze.com 2023-03-07 19:24 出处:网络
How do I fill map by a list of links names from a html code. clearly, I\'ve this code HTML: <div id=\"element-list\">

How do I fill map by a list of links names from a html code. clearly, I've this code HTML:

<div id="element-list">
<dl  id="element-template" class="element">
    <dd class="element element-1-0">                        
        <a class="element-name" hre开发者_JAVA技巧f="#">TEXT1</a> 
    </dd>       
    <dd class="element element-1-0">     
        <a  class="element-name" href="#">TEXT2</a>  
    </dd>       
    <dd class="element element-1-0">                      
        <a  class="element-name" href="#">TEXT3</a> 
    </dd>        
</dl>

I would like to recover in a map java Text1, Text2, Text3.

I get the first link (text1) in this manner:

String elmt = selenium.getText("css=a.element-name");

and this is normal, but I need to check all elements.

Could anyone help me by telling me the best way to do that?


 int count = selenium.getXpathCount("//a[@class='element-name']").intValue();
 for(int i =1 ; i <= count ; i ++){
         System.out.println(selenium.getText("//dd["+i+"]/a"));
 }

Does this help ?

0

精彩评论

暂无评论...
验证码 换一张
取 消