Finding the number of pagination buttons in Seleni

2019-09-06 03:43发布

问题:

Pagination is itself a last row of table "ContentPlaceHolder1_gvChannelList". I want to count the number of pages/number of columns in pagination table.

driver.findElements(By.id("//*[@id='ContentPlaceHolder1_gvChannelList']/tbody/tr[17]/td/table/tbody/tr/td")).size()

Is returning 0 though there are five columns/<td> tags.

html table element hierarchy

回答1:

You are searching by Id, but you gave xpath expression. Try

driver.findElements(By.xpath("//*[@id='ContentPlaceHolder1_gvChannelList']/tbody/tr[17]/td/table/tbody/tr/td")).size()