• 示例1-苏宁每日自动登录打卡-结合Au3


    
    public class SuningAutoClock
    {
        public static void AutoClock() throws IOException, InterruptedException {
            SuningAutoClock autoLoginSuning = new SuningAutoClock();
            autoLoginSuning.autoKick("234234","xxxxx");
    }
    
        public void autoKick(String userName, String password) throws InterruptedException, IOException
        {
    
            System.setProperty("webdriver.chrome.driver", "C:\my-program\chromedriver.exe");
            WebDriver dr = new ChromeDriver();
    
            try {
    
                dr.get("https://www.suning.com/");
    
                //等待登录组件加载完成
                (new WebDriverWait(dr, 10)).until(new ExpectedCondition<Boolean>()
                {
                    public Boolean apply(WebDriver d)
                    {
                        return d.findElement(By.cssSelector("a[href='javascript:SFE.base.logonurl();']")).isDisplayed();
                    }
                });
    
                //如果有新人弹出框,先关闭
                if (dr.findElement(By.cssSelector(".new-user")).isDisplayed())
                {
                    dr.findElement(By.cssSelector("i[name='index3_homepage1_xrtk_close']")).click();
                }
    
                //点击登录按钮
                dr.findElement(By.cssSelector("a[href='javascript:SFE.base.logonurl();']")).click();
    
                //等待登录页面加载完成
                (new WebDriverWait(dr, 10)).until(new ExpectedCondition<Boolean>()
                {
                    public Boolean apply(WebDriver d)
                    {
                        return d.findElement(By.xpath("/html/body/div[2]/div/div/div[1]/a[2]")).isDisplayed();
                    }
                });
    
                //点击账户登录
                dr.findElement(By.xpath("/html/body/div[2]/div/div/div[1]/a[2]")).click();
    
                //输入密码和账户
                dr.findElement(By.cssSelector("#userName")).sendKeys(userName);
                dr.findElement(By.cssSelector("#password")).sendKeys(password);
                //勾选自动登录框
                //WebElement autoLogin = dr.findElement(By.cssSelector("#rememberMe"))
    
                //如果展示滑块,则拖动滑块
                WebElement temp = dr.findElement(By.cssSelector(".dt_child_content_knob"));
                if( temp!=null && temp.isDisplayed() ) {
                    Process process = Runtime.getRuntime().exec("C:\Users\Administrator\Desktop\AU3\苏宁登陆页面拖动验证滑块.exe");
                    process.waitFor();
    
                    System.out.println("操作登陆滑块完成!!");
                    Thread.sleep(2000);
                }
                //点击登录按钮
                dr.findElement(By.cssSelector("#submit")).click();
    
                //等待"我的易购"按钮加载完成
                (new WebDriverWait(dr, 10)).until(new ExpectedCondition<Boolean>()
                {
                    public Boolean apply(WebDriver d)
                    {
                        return d.findElement(By.cssSelector(".mysuning-handle span")).isDisplayed();
                    }
                });
    
                //等待 我的易购页加载完成
                dr.findElement(By.cssSelector(".mysuning-handle span")).click();
    
                (new WebDriverWait(dr, 10)).until(new ExpectedCondition<Boolean>()
                {
                    public Boolean apply(WebDriver d)
                    {
                        return d.findElement(By.cssSelector(".radiu-btn")).isDisplayed();
                    }
                });
                dr.findElement(By.cssSelector(".radiu-btn")).click();
    
                //等待打开 打卡签到页面
                Thread.sleep(5000);
                for (String tempHandleId : dr.getWindowHandles())
                {
                    dr.switchTo().window(tempHandleId);
                    if (dr.getTitle().equals("打卡签到_苏宁会员_苏宁易购"))
                    {
                        //等待 点我打卡加载完成
                        new WebDriverWait(dr, 10);
    
                        //调用au3的脚本进行打卡
                        Runtime runtime = Runtime.getRuntime();
                        runtime.exec("C:\Users\Administrator\Desktop\AU3\苏宁打卡页面自动移动到打卡按钮.exe");
    
                        System.out.println("执行结束!!!");
                    }
                }
            }catch (Exception e){
                e.printStackTrace();
            }
            finally {
                Thread.sleep(5000);
                dr.quit();
            }
        }
    }
    
    //苏宁登陆页面拖动验证滑块.au3
    #include <MsgBoxConstants.au3>
    #include <AutoItConstants.au3>
    
    Example()
    
    Func Example()
        ;累列出所有窗口
        Local $aList = WinList()
    
        ; Loop through the array displaying only visable windows with a title.
        For $i = 1 To $aList[0][0]
    		;找到指定窗口
            If $aList[$i][0]== "用户登录 - Google Chrome" Then
    			$title = $aList[$i][0];
    			;激活窗口到最前
    			WinActivate($title);
    			;窗口最大化
    			WinSetState($title,"",@SW_MAXIMIZE);
    			MouseMove(840,440, 100);
    			//按下鼠标左键
    			MouseDown($MOUSE_CLICK_LEFT) ;
    			//移动鼠标
    			MouseMove (  900, 435 ,10 );
    			MouseMove ( 1050, 450 ,30 );
    			//松开左键
    			MouseUp($MOUSE_CLICK_LEFT);
    
            EndIf
        Next
    EndFunc   ;==>Example
    
    
    //苏宁打卡页面自动移动到打卡按钮.au3
    #include <MsgBoxConstants.au3>
    #include <AutoItConstants.au3>
    
    Example()
    
    Func Example()
        ;累列出所有窗口
        Local $aList = WinList()
    
        ; Loop through the array displaying only visable windows with a title.
        For $i = 1 To $aList[0][0]
    		;找到指定窗口
            If $aList[$i][0]== "打卡签到_苏宁会员_苏宁易购 - Google Chrome" Then
    			$title = $aList[$i][0];
    			;激活窗口到最前
    			WinActivate($title);
    			;窗口最大化
    			WinSetState($title,"",@SW_MAXIMIZE);
    			;移动到x-400,y-600位置打卡
    			MouseMove(450,420, 100);
    			MouseClick($MOUSE_CLICK_LEFT);
            EndIf
        Next
    EndFunc   ;==>Example
    
    
  • 相关阅读:
    生成随机数的三种方法
    老外最常说的二十句钻石级英语
    线性探查法实现的散列表(哈希表)类
    STL容器之间可以直接相互赋值使用
    用位向量实现集合抽象数据类型
    一个利用map统计一段英文文章中每个单词出现次数的小程序
    各种排序算法的稳定性和时间复杂度小结
    24佳句对译收藏
    SQL 将一个字段内用逗号分隔的内容分成多条记录
    SQL递归查询(with cte as)
  • 原文地址:https://www.cnblogs.com/Desneo/p/7345824.html
Copyright © 2020-2023  润新知