亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

封裝By以后,腳本只能打開登陸網頁,登陸不進去

封裝By以后,腳本只能打開登陸網頁,登陸不進去

qq_安曉東_lmpyGT 2018-05-15 19:22:12
package com.selenium.miyang.go;import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import org.openqa.selenium.WebElement;import org.openqa.selenium.chrome.ChromeDriver;import org.openqa.selenium.interactions.Actions;public class login { WebDriver driver; public void initDriver(){ System.setProperty("webdriver.chrome.driver", "D:\\wps\\selenium-2.42.2\\chromedriver.exe"); driver = new ChromeDriver(); driver.get("http://www.xianlaiwan.cn/user/newlogin/from_url"); driver.manage().window().maximize(); } /* *登陸腳本 *? */ public void loginScript() throws Exception{ this.initDriver(); String username = "17729597958"; String password = "andong527011764"; String userBy ="name"; String userElement = "email"; String passBy = "name"; String passElement = "password"; String buttonBy = "className"; String buttonElement = "moco-btn"; String headerBy = "id"; String headerElement = "header-avator"; String userInforBy = "className"; String userInforElement = "name"; Thread.sleep(2000); WebElement user = this.element(this.byStr(userBy, userElement)); user.isDisplayed(); WebElement userpass = this.element(this.byStr(passBy, passElement)); userpass.isDisplayed(); WebElement login_button = this.element(this.byStr(buttonBy, buttonElement)); login_button.isDisplayed(); user.sendKeys(username); userpass.sendKeys(password); login_button.click(); Thread.sleep(2000); WebElement header = this.element(this.byStr(headerBy, headerElement)); Actions action = new Actions(driver);//鼠標懸停 action.moveToElement(header).perform(); String userInfor = this.element(this.byStr(userInforBy, userInforElement)).getText(); System.out.println(userInfor); if(userInfor.equals("慕勒2472625")){ System.out.println("登陸成功"); }else{ System.out.println("登陸失敗"); } } /*封裝By*/ public By byStr(String by,String local ){ if(by.equals("id")){ return By.id(local); }else if(equals("name")){ return By.name(local); }else if(by.equals("className")){ return By.className(local); }else{ return By.xpath(local); } } /*封裝element*/ public WebElement element(By by){ WebElement ele=driver.findElement(by); return ele; } public static void main(String[] args) throws Exception{ login action = new login(); action.loginScript(); }}
查看完整描述

目前暫無任何回答

  • 0 回答
  • 0 關注
  • 1019 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號