shockwave
shockwave

Reputation: 3282

Select a checkbox based on a column value using XPath

I'm using selenium to automate the testing. I'm facing an issue with selecting the checkbox of a table row. So I'm using XPath to do this. I have to select the row based on the file name. Below is the HTML

HTML

<form id="Runs3" action="" method="post">
	<table id="data_Runs1" class="project-data project-show-borders project-has-col-totals">
		<tbody>
			<tr class="project-alternate-row">
				<td id="ext-gen3" class="project-selectors" nowrap="">
					<input type="checkbox" onclick="Region.selectRow(this);" value="234" name=".select" title="Select/unselect row"/>
					<span style="display: inline-block; width: 16px; height: 10px;"/>
				</td>
				<td id="ext-gen11" align="left">
					<a href="/key/module/essays/direct.view?runId=234">Study1_AS_06-20-16_1.xml</a>
				</td>
			</tr>
		</tbody>
	</table>
</form>

This is the XPATH that I tried

//form[@id='Runs3']//a[text()='Study1_AS_06-20-16_1.xml']/preceding-sibling:://input[@name='.select']

Upvotes: 1

Views: 1103

Answers (3)

neetigya goel
neetigya goel

Reputation: 66

Try with this xpath:- //form[@id='Runs3']//a[text()='Study1_AS_06-20-16_1.xml']/../preceding-sibling::td/input

It navigates to the parent column of the a tag and goes to the preceding column of the table containing the input...

Upvotes: 1

Saurabh Gaur
Saurabh Gaur

Reputation: 23835

Your xPath seems to be wrong try with below xPath :-

//a[text()='Study1_AS_06-20-16_1.xml']/preceding::input[@name='.select']

Note :- for more clarification about xPath need to follow this

Hope it will help you..:)

Upvotes: 1

alecxe
alecxe

Reputation: 474171

a is not a sibling to the desired input. Use preceding axis instead:

//a[. = 'Study1_AS_06-20-16_1.xml']/preceding::input

Upvotes: 2

Related Questions