0
votes

enter image description here

I need to locate each item and click on it. I tired this:

List<WebElement> allTournaments = driver.findElements(By.xpath("//*[@id='main-section']/div/div/section/div[1]/ul/li/div/div[1]/div"));
        for (WebElement tournament : allTournaments) {
tournament.click();
}

But got the error "element not visible"

The xpath of first element is //[@id='main-section']/div/div/section/div1/ul/li1/div/div1/div xpath of second element is //[@id='main-section']/div/div/section/div1/ul/li[2]/div/div1/div like wise..

can anybody help..?

HTML:

   <div class="header-toggle-area">
<div class="header-notification-area text-right ng-scope" ng-controller="notificationController">
</header>
<!--HEADER ENDS-->
<div class="content-wrap" style="padding-top: 60px;">
<aside id="main-sidebar">
<!--MAIN SIDEBAR ENDS-->
<main id="main-section">
<div class="main-content">
<div class="ng-scope" ng-controller="NewTournamentsController as tournaments">
<header class="member-title dt-title-main">
<section class="dashboard-tournaments-listing">
<div class="" ng-show="tournaments.Page==1">
<ul class="row dashboard-listing">
<!-- ngRepeat: running in tournaments.runningTournaments -->
<li class="dashboard-listing-items ng-scope" ng-repeat="running in tournaments.runningTournaments" style="">
<div class="dtslider-block">
<div class="dtslider-content">
<img ng-src="../../category/categoryDefault.jpg" alt="slider" src="../../category/categoryDefault.jpg"/>
<div class="hover-contents">
<div class="hc-timer">
<p>   Tournament ends in </p>
<div class="hct-ticker ng-binding">   04:30 - 26/11/16 </div>
</div>
<div class="hc-details">
<div class="hcd-block ng-hide" ng-show="running.JoinedPlayers>0">
<ul class="hc-icons">
</div>
</div>
</div>
1
Post the relevant HTML code as well!! Thanks!! - Sudharsan Selvaraj
HTML code is added with question - Amrutha
which element are you trying to click? the entire DIV or any specific element inside the DIV. - Sudharsan Selvaraj
In that div there are 4 boxes with the image of a player. Each box represents a quiz game. I want to click each box. - Amrutha
instead of clicking the div element,find the xpath for the image tag inside the div and click on it. The HTML block mentioned in the question doesn't have the complete code for the provided image. - Sudharsan Selvaraj

1 Answers

0
votes

Check if each element is visible and clickable as follows:

for (WebElement tournament : allTournaments) {
  if (tournament.isDisplayed()
      && ExpectedConditions.elementToBeClickable(tournament).equals(true)) {
    tournament.click();
  }
}