Many examples on the internet, but the last time you send the message when the element not visible error, because the page has two send buttons, after several twists and ends, finally finished.
Package Selenium_java;
Import java.util.List;
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 Login126email {
Static Webdriver Driver = new Chromedriver ();
public static void Main (string[] args) throws Interruptedexception {
Login_126_email ();
Send_126_email ();
Driver.close ();
}
public static void Login_126_email () throws interruptedexception{
System.setproperty ("Webdriver.chrome.driver",
"D:\\install\\selenium\\chromedriver2.25_win32\\chromedriver.exe");
Driver.get ("http://mail.126.com/");
Thread.Sleep (1000);//Must wait
Login
Driver.switchto (). frame (0);
Driver.findelement (by.name ("email")). Clear ();
Driver.findelement (by.name ("email")). SendKeys ("Testselenium");
Driver.findelement (By.name ("password")). Clear ();
Driver.findelement (By.name ("password")). SendKeys ("!@#$%^");
Driver.findelement (By.id ("Dologin")). Click ();
Thread.Sleep (1000);
}
public static void Send_126_email () throws interruptedexception{
Write
Webelement xiexin_element = driver.findelement (By.xpath ("//span[contains (., ' letter ')"));
Xiexin_element.click ();
Thread.Sleep (1000);
Webelement shoujianren_element = driver.findelement (By.classname ("Nui-editableaddr-ipt"));
Shoujianren_element.sendkeys ("washli2001@126.com");
Webelement zhuti_element = driver.findelement (By.xpath ("//input[@class = ' nui-ipt-input '][contains" (@id, ' _ Subjectinput ')])//Below a filtered submit love Oh can
Webelement zhuti_element = driver.findelement (By.xpath ("//input[contains (@id, ' _subjectinput ')"));
Zhuti_element.sendkeys ("Selenium automatically send 126 mail test");
Webelement youjianneirong_element = Driver.switchto (). FRAME (Driver.findelement (By.classname ("APP-editor-iframe")) ). Findelement (By.classname ("Nui-scroll"));
Youjianneirong_element.sendkeys ("Hello.") Here is the test message, please ignore it. Thank you. Send Mailbox Content ... ");
Driver.switchto (). Defaultcontent ();
Actions actions = new actions (driver);
list<webelement> Spanss = driver.findelements (By.xpath ("//span[contains (., ' send ')"));//Because there are two send buttons
for (Webelement Span:spanss) {
Actions.movetoelement (SPAN). Click (). Build (). Perform ();
}
Exit Login
Webelement tuichu_element = driver.findelement (By.linktext ("exit"));
Tuichu_element.click ();
}
}