Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include an attribute in an XPath selection

I am using selenium to move through the pages.

Following is the page source:

<td colspan="10" align="right">
                <input type="button" name="previous" value="Previous" onclick="this.form.action = 'coca-cola-north-america-group-company-37452.htm?previous=true&currentPage=6';this.form.submit();" > 
                <input type="hidden" name="currentPage" id="currentPage" value="6" />

                <input type="button" name="next" value="Next" onclick="this.form.action = 'coca-cola-north-america-group-company-37452.htm?next=true&currentPage=6';this.form.submit();" >
            </td>


<td colspan="10" align="right">
                <input type="button" name="previous" value="Previous" onclick="this.form.action = 'coca-cola-north-america-group-company-37452.htm?previous=true&currentPage=7';this.form.submit();" > 
                <input type="hidden" name="currentPage" id="currentPage" value="7" />

I am using seleniums click method to click the next page,

browser.find_element_by_xpath('//*[@name="next"]').click()                  

Now when I come to the last page (below is the source code) I get the same xpath (for next page link)--- with attribute disabled at the end. And I want selenium to stop here.

However I am not sure how to include the disabled attribute in the xpath.

                <input type="button" name="next" value="Next" onclick="this.form.action = 'coca-cola-north-america-group-company-37452.htm?next=true&currentPage=7';this.form.submit();" disabled>
            </td>
like image 306
Md. Mohsin Avatar asked Jul 18 '14 13:07

Md. Mohsin


1 Answers

Try:

//*[@name="next"][not(@disabled)]
like image 95
Eero Helenius Avatar answered Oct 29 '22 03:10

Eero Helenius