菜鸟金融登录页面的滑动验证码,selenium写法
# 获取拖动按钮位置并拖动 def slide_auth(self): try: time.sleep(random.randint(6, 8)) # check have slide verify elements or not if (self.driver.find_element(By.ID, "baxia-password")).is_displayed(): self.driver.switch_to.frame('baxia-dialog-content') element = self.driver.find_element(By.ID, "nc_1_n1z") slide_bar = self.driver.find_element(By.ID, "nc_1__scale_text") action = ActionChains(self.driver) action.move_to_element(element).pause(1).click_and_hold(element).pause(1).move_by_offset( slide_bar.size['width'] - element.size['width'], 0).pause(1).release() # mobile slider action.perform() MessageToSlack.post_message_to_slack("Slide the verification bar") self.driver.switch_to.parent_frame() time.sleep(random.randint(4, 6)) if (self.driver.find_element(By.ID, "baxia-password")).is_displayed(): counter1 = 0 while (self.driver.find_element(By.ID, "baxia-password")).is_displayed() and counter1 < 6: self.driver.switch_to.frame('baxia-dialog-content') wrapper = self.driver.find_element(By.ID, "nocaptcha") wrapper.click() time.sleep(random.randint(2, 3)) element = self.driver.find_element(By.ID, "nc_1_n1z") slide_bar = self.driver.find_element(By.ID, "nc_1__scale_text") action = ActionChains(self.driver) action.move_to_element(element).pause(1).click_and_hold(element).pause(1).move_by_offset( slide_bar.size['width'] - element.size['width'], 0).release() # mobile slider action.perform() MessageToSlack.post_message_to_slack("Slide the verification bar") self.driver.switch_to.parent_frame() time.sleep(random.randint(4, 6)) counter1 += 1 counter1 = 0 if (self.driver.find_element(By.ID, "baxia-password")).is_displayed(): raise Exception("Still cannot pass the slide certification after 5 attempt") except Exception as s: self.driver.get_screenshot_as_file( "./ScreenCap/" + datetime.datetime.now().strftime("%Y%m%d_%H%M%p") + ".png") MessageToSlack.post_message_to_slack(str(s)) self.teardown_method sys.exit()