Reputation: 602
i am new with selenium. I want to make a loop with spans. It should start with A character. 0-9 shouldnt be got in loop.
<div id="alpha">
<div class="alphabets">
<span data-value="0-9" class="alphabetSearch">0-9</span>
<span data-value="A" class="alphabetSearch active">A</span>
<span data-value="B" class="alphabetSearch">B</span>
<span data-value="C" class="alphabetSearch">C</span>
<span data-value="Ç" class="alphabetSearch">Ç</span>
<span data-value="D" class="alphabetSearch">D</span>
</div>
</div>
Upvotes: 1
Views: 1339
Reputation: 3004
try the following code:
List<WebElement> allspan= driver.findElements(By.cssSelector("#alpha>div>span"));
for (WebElement spanvalues: allspan) {
if(spanvalues.getText().equals("0-9")){
continue;
}
else{
//do your code
}
}
Upvotes: 1
Reputation: 3927
i am just providing some logic in java here.. i used xpath to collect required span elements, you can use any other appropriate locator.
//in java
List<WebElement> allalphabets=driver.findElements(By.xpath("//*[@id='alpha']/div/span"));
//starting from j=1, as 0 is for '0-9' which should not be in loop
for(int j=1; j<allalphabets.size();j++){
//do your logic here
//just to print text
System.out.println(allalphabets.get(j).getText());
}
Upvotes: 1