Nagarjuna Reddy
Nagarjuna Reddy

Reputation: 819

Not able to check the check box, exception "element not visible"

In an table which can contain more rows, user is searchable using the email id. After searching, selecting the first check box. But selenium is throwing the element not visible exception.

//*[@id='share_user']/tbody/tr1/td1//label

//*[@id='share_user']/tbody/tr1/td1//input

//label[@for='checkbox_416']

last identifier is dynamic. Still getting the element not visible exception.

Table code is mentioned below

<table class="table table-striped table-hover dataTable" id="share_user"
	aria-describedby="share_user_info">
	<thead>
		<tr role="row">
			<th class="small-cell sorting" role="columnheader" tabindex="0"
				aria-controls="share_user" rowspan="1" colspan="1" style="width: 137px;"
				aria-label="Share Profile : activate to sort column ascending">Share Profile </th>
			<th class="medium-cell sorting" role="columnheader" tabindex="0"
				aria-controls="share_user" rowspan="1" colspan="1" style="width: 523px;"
				aria-label="User Details: activate to sort column ascending">User Details</th>
			<th class="medium-cell sorting_asc" role="columnheader" tabindex="0"
				aria-controls="share_user" rowspan="1" colspan="1" style="width: 366px;"
				aria-sort="ascending" aria-label="Access: activate to sort column descending">Access</th>
		</tr>

	</thead>

	<tbody role="alert" aria-live="polite" aria-relevant="all">
		<tr class="odd">

			<td class="">
				<div class="checkbox check-default">

					<input name="checkUser" id="checkbox_416" value="416" class="shareCheck"
						type="checkbox">
						<label for="checkbox_416"></label>
				</div>
			</td>
			<td class=" ">
				<img src="" class="img-responsive display-inline share-image">
					<div class="display-inline">

						<p class="share-name">alexx</p>
						<p class="muted">
							<i class="fa fa-envelope" hidden="true"></i>
							<span>[email protected]</span>
						</p>
					</div>
			</td>

			<td style="vertical-align: middle;" class="  sorting_1">

				<div class="select2-container medium-cell" id="s2id_rolelink416"
					style="float:left;">
					<a href="javascript:void(0)" onclick="return false;" class="select2-choice"
						tabindex="-1">
						<span class="select2-chosen">PROFILE ADMIN</span>
						<abbr class="select2-search-choice-close"></abbr>
						<span class="select2-arrow">
							<b></b>
						</span>
					</a>
					<input class="select2-focusser select2-offscreen" id="s2id_autogen11"
						type="text">
						<div class="select2-drop select2-display-none select2-with-searchbox">
							<div class="select2-search">
								<input autocomplete="off" autocorrect="off"
									autocapitalize="off" spellcheck="false" class="select2-input"
									type="text">
							</div>
							<ul class="select2-results">
							</ul>
						</div>
				</div>
				<select name="profileUsers.roleId" id="rolelink416"
					class="medium-cell select2-offscreen" style="float:left;" tabindex="-1">
					<option value="6">PROFILE ADMIN</option>
					<option value="7">PROFILE AGENT</option>
					<option value="8">PROFILE VIEWER</option>
					<option value="196">profile role</option>

				</select>

			</td>

		</tr>
	</tbody>
</table>

providing the screen shots as well. xpath

html

Upvotes: 2

Views: 3188

Answers (4)

Maninder
Maninder

Reputation: 174

You can use the following expression, I have verified working fine.

driver.findElement(By.xpath("//*[@id='share_user']/tbody/tr[1]/td[1]/div")).click();

Upvotes: 0

Nagarjuna Reddy
Nagarjuna Reddy

Reputation: 819

Used this //*[@id='share_user']/tbody/tr[1]/td[1]/div worked

Upvotes: 0

SelThroughJava
SelThroughJava

Reputation: 331

Try this

int ele_size=driver.findElements(By.xpath("locator")).size();

driver.findElements(By.xpath("locator")).get(ele_size-1).click();

We might encounter element not visible exception if element matching the locator existed in the DOM but is not currently visible. So we have to take the size of the element in first statement then in next statement we have to take the first element from the list and click on element.

Upvotes: 0

Guy
Guy

Reputation: 50854

Try to use explicit wait with Expected Conditions

WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement checkbox = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='share_user']/tbody/tr[1]/td[1]//input")));
checkbox.click();

Upvotes: 1

Related Questions