List page, select a record

Source: Internet
Author: User
Tags new set

Note: When you add a record, the record has multiple cases in the list, the first page of the list, the last item on the last page of the list, any position in the list, and a target record for each page.

Situation one: When the newly added record is in any position in the list, select the record and click Select and then click the "Update New" button

The implementation code is as follows (contains the need to invoke other common methods):

/** * page-by-page comparison to obtain the corresponding product * Webs: All of the TR object, Dr:dr object */public static webelement getpoduct (list<webelement> wbs,webdriver DR) {int trnum=wbs.size ();//Gets the number of all TR objects in a page webelement wb=null;if (trnum>0) {for (int i = 0; i < Trnum; i++) {WB=WB S.get (i);//Gets the TR object string id=wb.findelement (By.classname ("Datagrid-cell")). GetText ();// Gets the value of a column in the TR System.out.println ("Product ID" +id), if (i<trnum) {//In the first page range if (id.equals (")") {//dr.findelement (By.xpath ( "/html/body/div[2]/div/div[2]/div[2]/div[2]/table/tbody/tr[1]/td[1]/div/input")). Click (); return WB;} else {wb=null;continue;}} else {//re-fetch a new set of TR objects for loop comparison return null;}}} return WB;} /** * Java extracts a number from a string * str: Passed over the string */public static list<string> Getnum (String str) {Str.trim ();//string Number=lnum . substring (3, 4);//directly gets the number in the string passed over (applies to a string containing only a number) list<string> ss=new arraylist<string> ();             For (String Sss:str.replaceAll ("[^0-9]", ","). Split (",")) {//First replace the non-number with "," and then use "," to split the string into an array if (Sss.length () >0)     Ss.add (SSS); }returnSS;}} 

  

/** * * * * * */@Test (enabled=true) public void Upproduct () {mj.jumpaccounts (DR);//trigger a first-level menu mj.jumpaccountst_1 (DR);// Trigger Level Two menu Tofram (DR, Frameid), if (!isexist (DR, By.classname ("Datagrid-cell-check")) {//Add new record when no record//addproduct ();} else {//To perform modifications when logging (cycle through each page to get the product that needs modification)//page Flip related code one: TR as a variable, loop to find the corresponding product and then perform the modification (the newly added record is not on the last page or the first page, but in any position)// Get the string that shows the total number of pages (page, pages) of string Lnum=ffind (DR, By.xpath ("/html/body/div[2]/div/div[3]/table")). Findelement (By.xpath ("/ Html/body/div[2]/div/div[3]/table/tbody/tr/td[8]/span ")). GetText (); String Number=demo.getnum (lnum). Get (0);//Gets the total number of pages int number1=integer.parseint (number);//convert to int type//Outer loop is whether you want to turn the page, Whether a page has a matching item, inside the call comparison whether there is a compound item loop for (int i = 1; I <= number1; i++) {list<webelement> trs=dr.findelement (By.xpath (" /html/body/div[2]/div/div[2]/div[2]/div[2]/table ")). Findelements (By.tagname (" tr "));//Get all the TR objects for each page webelement Wbtr=demo.getpoduct (TRS,DR);//Gets the specific Webelemnet object (TR object) if (wbtr!=null) {if (!wbtr.isselected ()) {WBTr.click ();//returns the corresponding object by clicking the check}else {System.out.println ("error when selecting Product");}} else {//Perform a paging operation Webelement Btn_next=ffind (DR, By.xpath ("/html/body/div[2]/div/div[3]/table/tbody/tr/td[10]/a/span /span/span ")); Btn_next.click ();D EMO.SLP (); continue;}}
String js= "document.getElementById (\" Updateproduct\ "). Click ()"; Exejs (Dr, JS);//Execute JS, (click the Modify Product button) DEMO.SLP (3000);

}
}
}

Case two: When the newly added record is in the last position of the last page of the list, select the record and click Select and then click the "Update New" button

The implementation code is as follows (contains the need to invoke other common methods):

/** * Java extracts a number from a string * str: Passed over the string */public static list<string> Getnum (String str) {Str.trim ();//string Number=lnum . substring (3, 4);//directly gets the number in the passed-in string (applies to a string that contains only one number) list<string>  ss=new arraylist<string> (); for ( String Sss:str.replaceAll ("[^0-9]", ","). Split (",")) {//First replace the non-number with "," and then use "," to split the string into an array         if (Sss.length () >0)             Ss.add (SSS);     } return SS;}}

  

/** * * * * * */@Test (enabled=true) public void Upproduct () {mj.jumpaccounts (DR);//trigger a first-level menu mj.jumpaccountst_1 (DR);// Trigger Level Two menu Tofram (DR, Frameid), if (!isexist (DR, By.classname ("Datagrid-cell-check")) {//Add new record when no record//addproduct ();} else {//have a record to perform a modification operation (cycle through each page to get the product that needs to be modified)//paging related code one: TR as a variable, loop to find the corresponding product and then perform the modification (when the newly added record is the last item on the last page)//Get the string of characters showing the total number of pages Lnum=ffind (DR, By.xpath ("/html/body/div[2]/div/div[3]/table")). Findelement (By.xpath ("/html/body/div[2]/div/div[ 3]/table/tbody/tr/td[8]/span ")). GetText (); String Number=demo.getnum (lnum). Get (0);//Gets the total number of pages int number1=integer.parseint (number);//convert to int type// If the newly added product is on the first page or the last page, you can go directly to that page and then compare to find the product that needs to be modified (when the record is added directly on the first or last page) if (number1>1) {///list has more than one page, And the newly added record is not on the first page when the last page, you need to click the last page webelement lastpag=ffind (DR, By.xpath ("/html/body/div[2]/div/div[3]/table/tbody/ tr/td[11]/a "));//Click the last page Lastpag.click ();D EMO.SLP (2000); List<webelement> Trs1=ffind (DR, By.xpath ("/html/body/div[2]/div/div[2]/div[2]/div[2]/table")). findElements (By.tagname ("tr"));//Get the last page of all TR objects int SIZE=TRS1.size (); int lastindex=size-1;//The index of the last bar Webelement Lastwb=trs1.get (lastindex);//Gets the last element of the interface Lastwb.click ();} else {//get the last piece of data for the interface list<webelement> Trs1=ffind (DR, By.xpath ("/html/body/div[2]/div/div[2]/div[2]/div[2]/ Table ")). Findelements (By.tagname (" tr "));//Get the first page all the TR object int size=trs1.size (); int lastindex=size-1;// The index of the last article Webelement Lastwb=trs1.get (lastindex);//Gets the last element of the interface Lastwb.click ();} String js= "document.getElementById (\" Updateproduct\ "). Click ()"; Exejs (Dr, JS);//Execute JS, (click the Modify Product button) DEMO.SLP (3000);}}

  

  

List page, select a record

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.