The form in which the contact item is paginated is in the following form:
To get the total number of pages, traverse the function of paging, but because pagination is implemented in JavaScript, the page refreshes after each click of the OK button, the webelement element expires and cannot traverse the next paging operation. Reported staleelementreferenceexception error, so for this operation toss a day or give up.
The following functions are implemented for paging operations:
(1) Get the total number of pages and output
(2) Traversal operation ' previous page ', ' next page ' button, to enable paging function
(3) Enter the number of pages in the text box to enter the number of pages, click OK to achieve page turn function
defpage (): Driver=Login.driver#Get Total PagesL.findid (Driver,"Laypageid") Total_pages= Len (l.findscss (Driver,"a[href= ' javascript:; ']")) Print("Total_pages is%s"%(total_pages))#Click the next page forIinchRange (total_pages-1): L.findclassname (Driver,"Next"). Click () #next: The next page of class name Time.sleep (2) #Click on the previous page forIinchRange (total_pages-1): L.findclassname (Driver,"prev").Click () #prev: Previous page of class name Time.sleep (2) #page entry in the input box, click forIinchRange (1,total_pages+1): L.findclassname (Driver,"Textboxid"). Send_keys (i)l.findclassname (Driver,"laypage_btn"). Click () time.sleep (2)
The above code is not the realization of the paging function, just to record the page in the implementation of the paging function encountered difficulties, so that later re-pick up the changes.
Selenium + Python automation Test unittest Framework Learning (vi) pagination