I have the code below which searches for an element. if the element is not found it click on the next page. What I want is, if the element is not found till the last page it should print "Element not found".
elpath=f"//span[contains(text(),[value})]"
while True:
time sleep(2)
try:
driver.find element_by_xpath(elpath).click()
break
except Exception:
if driver.find element_by_xpath("Xpath to click Next Page").is_enabled():
driver.find_element_by_xpath("Xpath to click Next Page").click()
else:
print("Element Not Found")
break
but when I checked driver.find element_by_xpath("Xpath to click Next Page").is_enabled() returns True even if the next button is disabled(i.e the last page of the list)
Please find below the HTML codes for the Next Button:
For Disabled Button
<button mat-icon-button="" type="button" class="mat-focus-indicator mat-tooltip-trigger mat-paginator-navigation-next mat-icon-button mat-button-base_mat-animation-noopable mat-button-disabled" aria-label="Next page" disabled="true">
<span class="mat-button-wrapper">
<svg viewBox="0 0 24 24" focusable="false" class="mat-paginator-icon"> <path d="M08 6G8.59 8.32 13.23 121-821 4L10 142-6b">
</Path>
</svg>
</span>
<span matripple="" class="mat-ripple mat-button-ripple mat-button-ripple-round"> </span><span class="mat-button-focus-overlay">
</span>
</button>
For Normal Button
<button mat-icon-button="" type="button" class="mat-focus-indicator mat-tooltip-trigger mat-paginator-navigation-next mat-icon-button mat-button-base_mat-animation-noopable" aria-label="Next page">
<span class="mat-button-wrapper">
<svg viewBox="0 0 24 24" focusable="false" class="mat-paginator-icon"> <path d="M08 6G8.59 8.32 13.23 121-821 4L10 142-6b">
</Path>
</svg>
</span>
<span matripple="" class="mat-ripple mat-button-ripple mat-button-ripple-round">
</span>
<span class="mat-button-focus-overlay">
</span>
</button>
Can anyone suggest an alternative method?
Thanks in Advance!!!
Try the below code once.