//遍历商品属性IDpublic void traverseAttribute(String idName,String ID){ int count = 0,sign = 0; for(int i=1;i<=30;i+=2){ //属性 ID<=30时 01,03,05,..... if (i<10){ idName = ID+"0" + i;} else { idName = ID + i;} LogUtil.i("ID: " + idName); int size=SoloExt2.getInstance().getCurrentWebElements(By.id(idName)).size(); LogUtil.i("size: " + size); if(size>0){ SoloExt2.getInstance().clickOnWebElement(idName); sign = 1; break; } } if(sign==0) { for (int i = 2; i <= 30; i+=2) { //属性 ID<=30时 02,04,06,....... if (i < 10) { idName = ID+"0" + i; } else { idName = ID + i; } LogUtil.i("ID: " + idName); int size = SoloExt2.getInstance().getCurrentWebElements(By.id(idName)).size(); LogUtil.i("size: " + size); if (size > 0) { SoloExt2.getInstance().clickOnWebElement(idName); sign = 1; break; } } } if(sign==0) { //属性 ID>1030时 while (count < 30) { int i = BaseFunc.getRandom(31,99); idName = ID + i; LogUtil.i("ID: " + idName); int size = SoloExt2.getInstance().getCurrentWebElements(By.id(idName)).size(); LogUtil.i("size: " + size); if (size > 0) { SoloExt2.getInstance().clickOnWebElement(idName); break; } else {count++;} } }}//选择商品属性public void selectAttribute() { String colourID = null,sizeID=null; LogUtil.i("++++++++++: " +SoloExt2.getInstance().getCurrentWebElements(By.id("sku_prop_2"))); LogUtil.i("++++++++++: " +SoloExt2.getInstance().getCurrentWebElements(By.id("sku_prop_2")).indexOf(0)); this.traverseAttribute(colourID,"sku_10"); //选择颜色属性 if (SoloExt2.getInstance().getCurrentWebElements(By.id("sku_prop_2")).size()>0){ this.traverseAttribute(sizeID,"sku_11"); //选择尺码属性 } SoloExt2.getInstance().sleepUnitTime();}
时间: 2024-11-05 16:04:30