Led
Led

Reputation: 517

Xpath - AND issue

What to do to select a specific element from a dynamic website with xpath? lets say on the following table: I would like to select the second row,

I plan to select the input image with "icon_edit" as source, but with my current xpath, it is selecting two of them.

  //*[normalize-space(td[1])="ok" and not(normalize-space(td[3])) and normalize-space(td[4]="Available")]//*[contains(@src, "icon_edit")]

<html>
	<body>
		<table>
			<tbody>
				<tr>
					<th>a</th>
					<th>b</th>
					<th>c</th>
					<th>d</th>
					<th>e</th>
					<th>f</th>
					<th>Actions</th>
				</tr>
				<tr>
					<td><span>ok</span></td>
					<td><span>has date</span></td>
					<td><span>has date</span></td>
					<td><span>Available</span></td>
					<td><span>1</span></td>
					<td><span></span></td>
					<td><input type="image" src="../../Images/icon_edit_Grey.gif">
						<input type="image" src="../../Images/icon_delete_Grey.gif">
					</td>
				</tr>
				<tr>
					<td><span>ok</span></td>
					<td><span>has date</span></td>
					<td><span></span></td>
					<td><span>Available</span></td>
					<td><span>1</span></td>
					<td><span></span></td>
					<td><input type="image" src="../../Images/icon_edit_Grey.gif">
						<input type="image" src="../../Images/icon_delete_Grey.gif">
					</td>
				</tr>
				<tr>
					<td><span>ok</span></td>
					<td><span>has date</span></td>
					<td><span></span></td>
					<td><span>Not Available</span></td>
					<td><span>1</span></td>
					<td><span></span></td>
					<td><input type="image" src="../../Images/icon_edit_Grey.gif">
						<input type="image"src="../../Images/icon_delete_Grey.gif">
					</td>
				</tr>
				<tr>
					<td><span>Not ok</span></td>
					<td><span>has date</span></td>
					<td><span></span></td>
					<td><span>Available</span></td>
					<td><span>2</span></td>
					<td><span></span></td>
					<td><input type="image" src="../../Images/icon_edit_Grey.gif">
						<input type="image" src="../../Images/icon_delete_Grey.gif">
					</td>
				</tr>
		<table>
	</body>
</html>

Upvotes: 2

Views: 37

Answers (1)

Andersson
Andersson

Reputation: 52665

You made a typo in third predicate. Just replace

normalize-space(td[4]="Available")

with

normalize-space(td[4])="Available"

Note that normalize-space(td[4]="Available") always return true while normalize-space(td[4])="Available" return true if required condition is met

Upvotes: 2

Related Questions