具有此特定名称的元素列表,我需要单击此元素 这是我的代码:
for(WebElement li : myElements)
{
System.out.println(li.getText());
System.out.println();
for (int i=0; i<Name.length(); i++)
{
if(li.getText().equalsIgnoreCase(Name[i]))
{
System.out.println("Matched");
//myElements.get(2).click();
}
}
}
这是我的HTML代码:
<div style="margin-right:30px;" class="rlbGroup rlbGroupRight">
<ul class="rlbList">
<li class="rlbItem rlbHovered" id="radListBoxSource_i0">
<span class="rlbText">Apex</span></li><li class="rlbItem" id="radListBoxSource_i1">
<span class="rlbText">ARC</span></li><li class="rlbItem" id="radListBoxSource_i2">
<span class="rlbText">Buckeye</span></li><li class="rlbItem" id="radListBoxSource_i3">
<span class="rlbText">Citgo</span>
</li>
<li class="rlbItem" id="radListBoxSource_i4">
<span class="rlbText">Colonial</span>
</li>
<li class="rlbItem" id="radListBoxSource_i5">
<span class="rlbText">KMEP North</span>
</li>
<li class="rlbItem" id="radListBoxSource_i6">
<span class="rlbText">KMEP South</span>
</li>
<li class="rlbItem" id="radListBoxSource_i7">
<span class="rlbText">KMEP West</span>
</li>
<li class="rlbItem" id="radListBoxSource_i8">
<span class="rlbText">Magellan</span>
</li>
<li class="rlbItem" id="radListBoxSource_i9">
<span class="rlbText">Magellan East</span>
</li>
<li class="rlbItem" id="radListBoxSource_i10">
<span class="rlbText">Magellan West</span>
</li>
<li class="rlbItem" id="radListBoxSource_i11">
<span class="rlbText">Marathon</span>
</li>
<li class="rlbItem" id="radListBoxSource_i12">
<span class="rlbText">Marathon East</span>
</li>
<li class="rlbItem" id="radListBoxSource_i13">
<span class="rlbText">Motiva</span>
</li>
<li class="rlbItem" id="radListBoxSource_i14">
<span class="rlbText">Motiva Shell</span>
</li>
<li class="rlbItem" id="radListBoxSource_i15">
<span class="rlbText">Motiva South</span>
</li>
<li class="rlbItem" id="radListBoxSource_i16">
<span class="rlbText">TPSI</span>
</li>
<li class="rlbItem" id="radListBoxSource_i17">
<span class="rlbText">TPSI East</span>
</li>
<li class="rlbItem" id="radListBoxSource_i18">
<span class="rlbText">Vecenergy</span>
</li>
</ul>
</div>
以这个名字来作为&#39; Motiva&#39;从excel sheet作为字符串。
任何人都可以帮我解决这个问题吗?
答案 0 :(得分:0)
这里有: 假设你的myElements如下:
List<WebElement> myElements =driver.findElements(By.cssSelector("li[class*='rlbItem']"));
for(WebElement li : myElements)
{
System.out.println(li.getText());
System.out.println();
for (int i=0; i<Name.length(); i++)
{
if(li.getText().equalsIgnoreCase(Name[i]))
{
//Clicks on the matched webelement
li.click();
}
}
}