def SetText(self, key, title): webcmd = WebDriverCmd(self.driver) pyperclip.copy(title) pyperclip.paste() webcmd.AddCmd2(CmdType.CLICK, key) webcmd.AddCmd2(CmdType.CTR_V, key) webcmd.Run(True)
def GetApkUrl(self, appid): html = self.GetHtml(appid) webcmd = WebDriverCmd(self.driver) strappid = "C" + appid key = "//div[@appid='" + strappid + "']" item = webcmd.Find(key) url = item.get_attribute("apkdownloadurl") print("apk=", url) return url
def CreateAdBanner(self, isHD): # self.driver.get("https://adnet.qq.com/placement/add") # https://adnet.qq.com/placement/60503466885129/add self.driver.get(self.urlCreatePlaceId) time.sleep(1) webcmd = WebDriverCmd(self.driver) time.sleep(3) # div class="card-inner" # list = self.driver.find_elements( # By.XPATH, "//div[@class='card-inner']") # list[4].click() # time.sleep(2) key = "//div[@class='card-inner']" webcmd.AddCmdList(CmdType.CLICK_Action, key, 4, 2) webcmd.Run(True) # <ul class="union-card-list card-list-banner list-contain-1" ul = self.driver.find_element( By.XPATH, "//ul[@class='union-card-list card-list-banner list-contain-1']") # bug # list = ul.find_elements(By.XPATH, "//li[@class='union-card-item']") # ok 查找子元素li list = ul.find_elements_by_xpath('li') li = list[0] li.click() time.sleep(1) # item = self.driver.find_element(By.XPATH, "//input[@class='spaui-input has-normal spaui-component']") list = self.driver.find_elements(By.XPATH, "//input[@type='text']") # self.driver.execute_script("arguments[0].scrollIntoView();", item) # self.driver.execute_script('window.scrollTo(0,1000000)') time.sleep(1) list[1].send_keys("b") # upload image item = self.driver.find_element( By.XPATH, "//button[@id='spaui-uploader_2-empty']") item.click() time.sleep(1) self.OpenFileBrowser() time.sleep(1) # finish item = self.driver.find_element( By.XPATH, "//button[@class='union-complete-btn spaui-button spaui-button-primary spaui-component']" ) item.click() time.sleep(1)
def Login(self, user, password): self.urlold = self.driver.current_url print("Login urlold=", self.urlold) webcmd = WebDriverCmd(self.driver) webcmd.AddCmdWait(CmdType.CLICK_Action, "//div[@class='btn-login']") webcmd.Run(True) webcmd.AddCmd(CmdType.INPUT, "//input[@id='uc-common-account']", user) webcmd.AddCmd(CmdType.INPUT, "//input[@id='ucsl-password-edit']", password) # 登录 # <div class="login-action"> # webcmd.AddCmd(CmdType.CLICK_Action,"//input[@id='submit-formt']") # webcmd.AddCmd(CmdType.CLICK_Action,"//div[@class='login-action']") webcmd.Run(True) # self.LoginQQ(user, password) # self.SaveCookie() # 等待登录成功 while True: time.sleep(1) self.urlnew = self.driver.current_url print("Login urlnew=", self.urlnew) if self.urlnew != self.urlold: print("Login Finish =", self.urlnew) break
def UploadImage(self, isAuto): print('UploadImage isAuto', isAuto) webcmd = WebDriverCmd(self.driver) if isAuto == True: key = "//button[@id='spaui-uploader_2-empty']" webcmd.AddCmd(CmdType.CLICK_Action, key) webcmd.Run(True) time.sleep(1) self.OpenFileBrowser() time.sleep(3) else: key_press = 'q' while True: #making a loop time.sleep(1) print('waiting for key press = ', key_press) # try: if keyboard.is_pressed(key_press): print('You Pressed A Key!') break
def OnClickFinish(self): webcmd = WebDriverCmd(self.driver) keyFinish = "//button[@class='union-complete-btn spaui-button spaui-button-primary spaui-component']" webcmd.AddCmd(CmdType.CLICK_Action, keyFinish) webcmd.Run(True) key = "//div[@class='text title' and text()='请上传广告位展示截图']" if webcmd.IsElementExist(key): # 确定 key = "//button[@class=' t']" webcmd.AddCmd(CmdType.CLICK_Action, key) webcmd.Run(True) # 重新上传 time.sleep(1) print("请上传广告位展示截图") self.UploadImage(False) webcmd.AddCmd(CmdType.CLICK_Action, keyFinish) webcmd.Run(True)
def CreateAdVideo(self, isHD): webcmd = WebDriverCmd(self.driver) # self.driver.get("https://adnet.qq.com/placement/add") # https://adnet.qq.com/placement/60503466885129/add self.driver.get(self.urlCreatePlaceId) time.sleep(1) time.sleep(3) # div class="card-inner" key = "//div[@class='card-inner']" webcmd.AddCmdList(CmdType.CLICK_Action, key, 2, 2) webcmd.Run(True) # item = self.driver.find_element(By.XPATH, "//input[@class='spaui-input has-normal spaui-component']") list = self.driver.find_elements(By.XPATH, "//input[@type='text']") # self.driver.execute_script("arguments[0].scrollIntoView();", item) # self.driver.execute_script('window.scrollTo(0,1000000)') time.sleep(1) list[1].send_keys("v") # upload image # item = self.driver.find_element( # By.XPATH, "//button[@id='spaui-uploader_2-empty']") # item.click() # time.sleep(1) # self.OpenFileBrowser() # time.sleep(1) self.UploadImage(True) # finish # item = self.driver.find_element( # By.XPATH, "//button[@class='union-complete-btn spaui-button spaui-button-primary spaui-component']") # item.click() # time.sleep(1) # finish self.OnClickFinish()
def CreateApp(self, isHD): self.driver.get( "http://union.baidu.com/bqt/appco.html#/promotion/application/create" ) time.sleep(1) webcmd = WebDriverCmd(self.driver) appChannel = source.TAPTAP appid = AppInfo.GetAppId(isHD, source.TAPTAP) if appid == "0": appid = AppInfo.GetAppId(isHD, source.HUAWEI) appChannel = source.HUAWEI key = "//input[@type='text' and @name='name']" title = self.GetAppName(isHD) self.SetText(key, title) # 行业 key = "//div[@class='veui-select veui-select-empty']" div = webcmd.Find(key) key = ".//button[@aria-haspopup='listbox']" item = webcmd.FindChild(div, key) item.click() time.sleep(1) key = "//span[@class='veui-option-label' and text()='教育']" webcmd.AddCmd(CmdType.CLICK, key) webcmd.Run(True) time.sleep(1) key = "//span[@class='veui-option-label' and text()='儿童']" webcmd.AddCmd(CmdType.CLICK, key) webcmd.Run(True) key = "//input[@type='text' and @name='keyword']" title = self.GetAppName(isHD) self.SetText(key, title) key = "//textarea[@class='veui-textarea-input']" title = AppInfo.GetAppDetail(isHD, source.LANGUAGE_CN) self.SetText(key, title) # <button type="button" class="veui-button"> Android </button> if self.osApp == source.ANDROID: key = "//button[@class='veui-button' and contains(text(),'Android')]" webcmd.AddCmd(CmdType.CLICK, key) webcmd.Run(True) key = "//input[@type='text' and @name='packageName']" title = AppInfo.GetAppPackage(self.osApp, isHD) self.SetText(key, title) #应用市场 http://app.mi.com/details?id=com.kibey.prophecy if self.osApp == source.ANDROID: key = "//button[@class='veui-button veui-dropdown-button']" webcmd.AddCmd(CmdType.CLICK, key) webcmd.Run(True) time.sleep(1) key = "//span[@class='veui-option-label' and text()='华为应用市场']" webcmd.AddCmd(CmdType.CLICK, key) webcmd.Run(True) key = "//input[@type='text' and @name='appUrl']" # http(s)://appdl-drcn.dbankcdn.com/xxx或者http(s)://appdlc-drcn.hispace.hicloud.com/xxx # http://appdlc-drcn.hispace.hicloud.com/dl/appdl/application/apk/7c/7c1e552794ec43d488e9149e6c4644a7/com.ss.android.ugc.aweme.lite.2007201350.apk apk_url = mainAppVersionHuawei.GetApkUrl( AppInfo.GetAppId(isHD, source.HUAWEI)) self.SetText(key, apk_url) old_window = self.driver.current_window_handle # 下一步 # <button ui="primary" type="submit" class="veui-button">下一步</button> key = "//button[@ui='primary' and @type='submit']" webcmd.AddCmd(CmdType.CLICK, key) webcmd.Run(True) # 跳转到新的页面 print("self.driver.current_url=", self.driver.current_url) # self.driver.switch_to.window(self.driver.window_handles[0]) for win in self.driver.window_handles: if win != old_window: self.driver.switch_to.window(win) time.sleep(2) print("self.driver.current_url 2=", self.driver.current_url) if self.osApp == source.ANDROID: # E:\Users\moon\Downloads downloadDir = "C:\\Users\\moon\\Downloads" self.DeleteAllDownloadApk(downloadDir) # 下载空包 E:\Users\moon\Downloads\mssp-verify-b8920a35.apk key = "//button[@class='veui-button bottom20']" webcmd.AddCmd(CmdType.CLICK, key) webcmd.Run(True) time.sleep(3) apk_unsign = self.GetDownloadApk(downloadDir) apk_sign = "F:\\sourcecode\\mssp_baidu\\signed.apk" jks = "F:\\sourcecode\\unity\\product\\kidsgame\\ProjectConfig\\Ad\\moonma.jks" # sign apk: # jarsigner -verbose -keystore ~/sourcecode/mssp_baidu/moonma.jks -signedjar ~/sourcecode/mssp_baidu/signed.apk ~/sourcecode/mssp_baidu/empty.apk moonma -storepass qianlizhiwai cmd = "jarsigner -verbose -keystore " + jks + " -signedjar " + apk_sign + " " + apk_unsign + " moonma -storepass qianlizhiwai" print(cmd) os.system(cmd) time.sleep(1) # sign end # 滚动到浏览器顶部 js_top = "var q=document.documentElement.scrollTop=0" # 滚动到浏览器底部 js_bottom = "var q=document.documentElement.scrollTop=document.documentElement.scrollHeight" self.driver.execute_script(js_bottom) time.sleep(2) # 上传签名包 # key = "//input[@accept='.apk' and @name='file']" key = "//label[@class='veui-button veui-uploader-input-label']" item = webcmd.AddCmd(CmdType.CLICK_Action, key) # webcmd.SetItemVisible(item) webcmd.Run(True) self.OpenFileBrowser(apk_sign) if self.osApp == source.IOS: time.sleep(3) # 完成 key = "//button[@ui='primary' and @type='submit']" webcmd.AddCmd(CmdType.CLICK_Action, key) webcmd.Run(True)