Java Selenium Send 126 messages To resolve element not Visible__selenium

Source: Internet
Author: User
Tags xpath

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 ();

}

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.