import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.openqa.selenium.By;
public class Example {
// Mooctest Selenium Example
// <!> Check if selenium-standalone.jar is added to build path.
public static void test(WebDriver driver) throws InterruptedException {
// TODO Test script
driver.get("https://weibo.com/newlogin?tabtype=weibo&gid=102803&url=");
Thread.sleep(5000);
driver.findElement(By.xpath("//[@id=\"app\"]/div[1]/div[1]/div/div/div[2]/div[2]/div/input")).sendKeys("一条小团团OvO");
Thread.sleep(1000);
driver.findElement(By.xpath("//*[@id=\"app\"]/div[1]/div[1]/div/div/div[2]/div[2]/button")).click();
Thread.sleep(3000);
String win =driver.getWindowHandle();
Set<String>Windows=driver.getWindowHandles();
List<String>allWindows=new ArrayList<String>(Windows);
int j=0;
for (int i=0;i<allWindows.size();i++) {
if(!allWindows.get(i).equals(win)) {
j=i;
}
}
driver.close();
Thread.sleep(2000);
driver.switchTo().window(allWindows.get(j));
driver.findElement(By.xpath("//[@id=\"pl_feedlist_index\"]/div[2]/div[1]/div/div[2]/div/a")).click();
Thread.sleep(3000);
win =driver.getWindowHandle();
Windows=driver.getWindowHandles();
allWindows=new ArrayList<String>(Windows);
for (int i=0;i<allWindows.size();i++) {
if(!allWindows.get(i).equals(win)) {
j=i;
}
}
driver.close();
Thread.sleep(1500);
driver.switchTo().window(allWindows.get(j));
}
public static void main(String[] args) {
// Run main function to test your script.
WebDriver driver = new ChromeDriver();
try { test(driver); }
catch(Exception e) { e.printStackTrace(); }
finally { driver.quit(); }
}
}