如何从li标签中提取文本,这些文本再次出现在selenium webdriver中的另一个li标签下

时间:2013-12-04 10:27:18

标签: selenium-webdriver

下面是我想要选择子级别层次结构的自定义下拉列表的HTML,我无法添加代码,因此我附加了HTML的图像

![This is the image of the HTML of my code in which there are li tags under one li tag and I want to extract text of all li tags][1]


<ul id="selhierarchy" class="mcdropdown_menu" style="position: absolute; top: 604px; left: 486px; display: block; z-index: 999999; visibility: visible; height: 44px;">
<li class="mc_root mc_parent" rel="5" style="margin-left: 0px; margin-top: 0px; width:     297px;">
Key_element1.1
<ul style="display: none; z-index: 999999; top: 27px; left: 0px; visibility: visible; height: 22px;">
<li class="mc_parent mc_endcol" rel="12" style="margin-left: 0px; margin-top: 0px; width: 150px;">
Key_element2.1
<ul style="display: none; z-index: 999999; top: 23px; left: 0px; visibility: visible; height: 22px;">
<li class="mc_endcol" rel="13" style="margin-left: 0px; margin-top: 0px; width: 150px;">Key3.1</li>
</ul>
</li>
</ul>
</li>
<li class="mc_root mc_parent mc_endcol" rel="6" style="margin-left: 0px; margin-top: 0px; width: 297px;">
Key_element1.2
<ul style="display: none; z-index: 999999; top: 50px; left: 0px; visibility: visible; height: 22px;">
<li class="mc_parent mc_endcol" rel="14" style="margin-left: 0px; margin-top: 0px; width: 150px;">
Key_element2.1
<ul style="display: none; z-index: 999999; top: 23px; left: 0px; visibility: visible; height: 44px;">
<li class="" rel="15" style="margin-left: 0px; margin-top: 0px; width: 150px;">Key3.2</li>
<li class="mc_endcol" rel="16" style="margin-left: 0px; margin-top: 0px; width: 150px;">Key3.1</li>

1 个答案:

答案 0 :(得分:0)

WebElement we = driver.findElement(By.tagname("li")); // Parent element
WebElement we1 = we.findElement(By.tagname("li")); // child element

String arg = we1.getText(); 
System.out.println(arg);