Selenium (Java) Example Two

OBJECTIVE: Netease cloud album Comments 

Step: Visit NetEase cloud Gallery Home - Login account - into my album - into each album and add comments

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class AddComment {

	public static void main(String[] args) {
		//访问相册首页
		System.setProperty("webdriver.firefox.bin","D:\\Mozilla Firefox\\firefox.exe");
		WebDriver driver = new FirefoxDriver(); 
		driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
		driver.get("http://photo.163.com/");
		
		//切换到登录信息所在的frame
		WebElement login_frame = driver.findElement(By.xpath("//body//aside//iframe"));
		driver.switchTo().frame(login_frame);
		WebElement login_frame_inner = driver.findElement(By.xpath("//div[@id='login-URS-iframe']/iframe"));
		driver.switchTo().frame(login_frame_inner);
		
		//输入账号和密码,登陆账号
		WebElement input_email = driver.findElement(By.name("email"));
		input_email.clear();
		input_email.sendKeys("[email protected]");//输入账号
		WebElement input_pw = driver.findElement(By.name("password"));
		input_pw.sendKeys("xxxxxx");//输入密码
		driver.findElement(By.id("dologin")).click();
		
		//切换到frame外面
		driver.switchTo().defaultContent();
		driver.switchTo().defaultContent();
		
		//进入我的相册
		driver.findElement(By.linkText("进入我的相册")).click();
		
		//选择相册进入并添加评论
		List<WebElement> albums = driver.findElements(By.cssSelector("div.item>.ln.ln0>a>img"));
//		System.out.println("我的相册里有"+albums.size()+"个相册。");
		for (WebElement album:albums) {
			album.click();
			driver.switchTo().frame(driver.findElement(By.xpath("//div[@class='j-main']//iframe")));
			driver.findElement(By.xpath("//body")).sendKeys("好美啊");
			driver.switchTo().defaultContent();
			driver.findElement(By.cssSelector("input[value='发表']")).click();
			//回到我的相册首页
			driver.navigate().back();
		}
		
	}

}

problem:

NetEase album feels not easy to use, very slow page loads, test time super long, often timeout exception, should consider reducing load time, ranging from finished loading on to the next step; or directly on another website practicing it, tired heart. . .

Published 37 original articles · won praise 47 · Views 100,000 +

Guess you like

Origin blog.csdn.net/u013378642/article/details/81676019