ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

登录滑块处理

2022-02-23 13:32:29  阅读:80  来源: 互联网

标签:LOC 滑块 登录 处理 doc self element text login


coding = utf-8

Date: 2021/5/12 16:33

import time

from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from AutoWebUi.PageLocators.login_pagelocators import LoginPageLocators as LOC
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.common.exceptions import StaleElementReferenceException
from AutoWebUi.Common.basepage import BasePage

class LoginPage(BasePage):

#元素定位--通过find_element_by_xpath的底层方法,find_element传入元组(方法,值),使用时find_element(*self.xx),*解包
#以下元素存入PageLocators.login_pagelocators中
# name_text = (By.XPATH,'//*[@id="u"]')
# pwd_text = (By.XPATH,'//*[@id="p"]')
# login_button = (By.XPATH,'//*[@id="login_button"]')
# remberuser_check = (By.XPATH,'//*[@id="p_low_login_enable"]')
# login_tips=(By.XPATH,'//div[@class="loginTips"]')

#登录操作
def login(self,username,password,rember_user=False):
    # 以下元素存入PageLocators.login_pagelocators中
    # name_text='//*[@id="u"]'
    # pwd_text='//*[@id="p"]'
    # login_button='//*[@id="login_button"]'
    # remberuser_check='//*[@id="p_low_login_enable"]'
    #切换iframe
    #登陆页面
    doc ="登录页面_登录功能"
    self.driver.switch_to.frame("login_frame")
    time.sleep(0.5)
    self.wait_eleVisible(LOC.name_text,doc=doc)
    # WebDriverWait(self.driver,30).until(EC.visibility_of_element_located(LOC.name_text))
    self.input_text(LOC.name_text,username,doc=doc)
    # self.driver.find_element(*LOC.name_text).send_keys(username)
    self.input_text(LOC.pwd_text,password,doc=doc)
    # self.driver.find_element(*LOC.pwd_text).send_keys(password)
    #判断rember_user的值,决定是否勾选
    if rember_user==False:
        pass
    else:
        self.click_element(LOC.remberuser_check,doc=doc)
    self.click_element(LOC.login_button,doc=doc)
    time.sleep(2)
    #QQ邮箱登录图片滑块处理
    try:
        #进入iframe
        self.driver.switch_to.frame('tcaptcha_iframe')          #tcaptcha_iframe
        time.sleep(1)
        WebDriverWait(self.driver,10).until(EC.presence_of_element_located(LOC.login_slider))
        start_position=self.driver.find_element_by_id('tcaptcha_drag_button')       #tcaptcha_drag_button
        time.sleep(2)
        action=ActionChains(self.driver)
        action.click_and_hold(start_position).perform()    #鼠标移动到滑块初始位置,并保持点击不释放
        action.reset_actions()                              #清除已经存储操作
        #向水平向右滑块120
        action.move_by_offset(xoffset=120,yoffset=0).perform()
        time.sleep(1)
        #再每次移动距离+10
        try:
            for i in range(10):
                action.move_by_offset(xoffset=10, yoffset=0).perform()
                action.reset_actions()
                time.sleep(1)
        except StaleElementReferenceException:
            time.sleep(5)
        # time.sleep(10)
        # doc = '首页_个人账号元素检查'
        # result=self.isExist_ele(LOC.user_msg,doc=doc)
        # print("{}查询结果{}".format(doc, self.isExist_ele(LOC.user_msg, doc=doc)))
        # return result

    except:
        pass

#注册入口
def register_enter(self):
    pass

#获取错误信息提示
def get_errorMsg_from_loginArea(self):
    #登陆页面
    doc ="登录页面_登录区域的错误提示"
    # 切换iframe
    self.driver.switch_to.frame("login_frame")
    self.wait_eleVisible(LOC.login_tips,doc=doc)
    # WebDriverWait(self.driver,10).until(EC.presence_of_element_located((By.XPATH,'//div[@class="loginTips"]')))
    return self.get_text(LOC.login_tips,doc=doc)
    # return self.driver.find_element_by_xpath('//div[@class="loginTips"]').text

标签:LOC,滑块,登录,处理,doc,self,element,text,login
来源: https://blog.csdn.net/qq_43147274/article/details/123087835

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有