I got a list of webelement using xpath = ".//div[@id='list']/ul/li"
now li tag has child tags
<div class="abc-box " tabindex="-1">
<div class="abc-img b-loaded" tabindex="-1" style="background-image: url("/binaries/abc.jpg");">
<a class="game-img__link" data-gameid="1569" tabindex="-1" title="abc" href="/1816/launchSocialGame.do?launch=real" rel="nofollow">abc</a>
</div>
<div class="abc-overlay" tabindex="-1">
<a class="abc-overlay__link" data-gameid="1569" href="/1816/launch.do?launch=real" tabindex="-1" rel="nofollow">Play</a>
</div>
</div>
I am successfully getting <a>
inside first <div>/<div>
to verify the title="abc"
. Now if title=abc
, I need to click second<a>
as on mouseover/click on the webelement(image) of the list, play button get overlayed.
code i am using
public void click(String gameName) {
Webelement list=getDriver().findElement(xpath = ".//div[@id='list']/ul/li");
Iterator var2 = this.list.iterator();
while(var2.hasNext()) {
WebElement we = (WebElement)var2.next();
WebElement gameImage= we.findElement(By.tagName("a"));
if (gameImage.getAttribute("title").toLowerCase().contains(gameName.toLowerCase())) {
withTimeoutOf(SECONDS_TO_WAIT, TimeUnit.SECONDS);
(new WebElement playLink = we.findElement(By.className("abc-overlay__link")); withTimeoutOf(SECONDS_TO_WAIT, TimeUnit.SECONDS).waitFor(ExpectedConditions.visibilityOf(playLink));
playLink.sendKeys(Keys.RETURN);
clickedGame=true;
break;
}else{
clickedGame=false;
}
}
}
With above code, I am getting exception of timeout on
withTimeoutOf(SECONDS_TO_WAIT, TimeUnit.SECONDS).waitFor(ExpectedConditions.visibilityOf(playLink));
Tried many thing to get correct locator of play button but all attempts unsuccessful. I am not able to understand where am I doing wrong.
Please suggest how to click on play button.
Thanks