Selenium find_element_by_xpath last
<p>I have a bunch of elements and need to select last one using xpath.
The elements looks like:</p>

<pre><code>xpath=(//a[contains(text(),'Actions')])[2]
xpath=(//a[contains(text(),'Actions')])[3]
xpath=(//a[contains(text(),'Actions')])[4]
xpath=(//a[contains(text(),'Actions')])[5]
xpath=(//a[contains(text(),'Actions')])[6]
xpath=(//a[contains(text(),'Actions')])[7]
</code></pre>

<p><a href="http://prntscr.com/cc3gxd" rel="nofollow">http://prntscr.com/cc3gxd</a></p>

<p>Using Selenium IDE, I see, that I can select last element, by using:</p>

<pre><code>xpath=(//a[contains(text(),'Actions')])[last ()]
</code></pre>

<p>But Selenium Webdriver does not understand this syntax (error NoSuchElementException)</p>

<p>It only understands this syntax:</p>

<pre><code>driver.find_element_by_xpath("//a[contains(text(),'Actions')][last ()]").click()
</code></pre>

<p>But in this case I will select first element.</p>

<p>Please help me to rewrite xpath to select last element instead of first in Selenium Webdriver.</p>

<p>Your code is selecting first because you are using find element by xpath try </p>

<pre><code>ele=  driver.find_elements_by_xpath("//a[contains(text(),'Actions')][last ()]")
ele[-1].click
</code></pre>

python selenium xpath