日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Selenium应用代码(登录)

發布時間:2023/12/31 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Selenium应用代码(登录) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這篇可以不看,主要是為了以后的應用代碼(傳參)做鋪墊。

import java.awt.Rectangle;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.imageio.ImageIO;

import org.openqa.selenium.By;
import org.openqa.selenium.Point;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;

public class Login {
public static int t = 1;


static WebDriver driver = new ChromeDriver();


public void Loginindex(String url,String user,String pass) throws InterruptedException{

driver.get(url);

// 用下面代碼也可以實現
// driver.navigate().to("url");
// 獲取 網頁的 title
// System.out.println("1 Page title is: " + driver.getTitle());
// 通過 id 找到 input 的 DOM
// try{
// WebElement element0 =driver.findElement(By.xpath("//div[contains(@class,'user-info-mission-luckdraw-mask-body-close')]"));
// element0.click();
// }catch(Exception e){
// System.out.println("廣告沒有了");
// //System.exit(0);
// }
WebElement element = driver.findElement(By.xpath("//button[contains(@class,'Login')]"));
// 輸入關鍵字
element.click();
Thread.sleep(3000);
WebElement frame = driver.findElement(By.xpath("//*[@id='C_maijia-login']/div/div/div/iframe"));
driver.switchTo().frame(frame);
WebElement element1 =driver.findElement(By.xpath("//input[@name='loginCode']"));
element1.sendKeys(user);
WebElement element2 =driver.findElement(By.xpath("//input[@name='loginPassword']"));
element2.sendKeys(pass);;
WebElement button =driver.findElement(By.xpath("//button[contains(.,'登錄')]"));
button.click();
}


}

轉載于:https://www.cnblogs.com/testwang/p/5286681.html

總結

以上是生活随笔為你收集整理的Selenium应用代码(登录)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。