/a
means select the element a
from the root.
When you want to select li without a a
as decsendant try this:
driver.find_element(By.XPATH, '//*[@id="pagination"]/ul/li[2][not(.//a[@href])]')
When you want to select li without a a
as child try this:
driver.find_element(By.XPATH, '//*[@id="pagination"]/ul/li[2][not(a[@href])]')
or
driver.find_element(By.XPATH, '//*[@id="pagination"]/ul/li[2][not(./a[@href])]')
where the .
current context.
EDIT
This is how your context-html looks like:
<div id="pagination">
<ul>
<li class="previous"><input type="submit" name="in_prevBut" value="Previous" class="buttonPrev" border="0"/></li>
<li>
<a href="#" onmouseover="window.status='Page 1'; return true;">1</a>
2
<a href="#" onmouseover="window.status='Page 3'; return true;">3</a>
<a href="#" onmouseover="window.status='Page 4'; return true;">4</a>
<a href="#" onmouseover="window.status='Page 5'; return true;">5</a>
<a href="#" onmouseover="window.status='Page 6'; return true;">6</a>
<a href="#" onmouseover="window.status='Page 7'; return true;">7</a>
<a href="#" onmouseover="window.status='Page 8'; return true;">8</a>
<a href="#" onmouseover="window.status='Page 9'; return true;">9</a>
<a href="#" onmouseover="window.status='Page 10'; return true;">10</a>
</li>
</ul>
</div>
I have navigated to page 2, and we need that number (2).
Since the desired text-string is between a-elements you will need this XPath:
//*[@id="pagination"]/ul/li[2]/text()[string-length(translate(.," &160;","")) > 1]
 
=
This will select the text-string with the value of the current page.