The operation of the element has
1. Clear text
2. Analog Key input
3. Click the element
4. Return element dimensions
5. Get text
6. Get Property values
7. Determine if it is visible
8. Submit
The following is a script to show how to use the registration interface of Sina Mail
Source:
Packagecom.test.elementoperation;Importorg.openqa.selenium.By;ImportOrg.openqa.selenium.WebDriver;Importorg.openqa.selenium.WebElement;ImportOrg.openqa.selenium.firefox.FirefoxDriver; Public classElementoperationemail { Public Static voidMain (string[] args) {Webdriver driver=NewFirefoxdriver (); Driver.get ("Https://mail.sina.com.cn/register/regmail.php"); Driver.manage (). window (). Maximize (); //get the Email Name input box node and enter a nameWebelement emailname = driver.findelement (By.cssselector ("[Name=email]")); Emailname.clear (); Emailname.click (); Emailname.sendkeys (Allinfo.emailname); //get the email Password input box node, before entering the password, verify the email name is available, if available, continue, if not available, exit the browserWebelement Emailpassword = driver.findelement (By.cssselector ("[NAME=PSW]")); Emailpassword.click ();//Click the Password box to make the email name verification information appearWaitTime (3000); //get the email name Verification information node and determine if the information is "left arrow"Webelement CheckName =driver. Findelement (By.xpath ("Html/body/div[2]/div/div/div/div/form[1]/div[2]/ul/li[1]/div[3]/i")); String checkcontent= Checkname.gettext ();//get node text information by GetText methodSystem.out.println ("Verify that the user name information exists:" + checkname.isdisplayed () + "information about the result is:" +checkcontent); //get to the information and start judging and make a different branch if("Left Arrow". Equals (checkcontent)) { //Enter the password after confirming the name is correctEmailpassword.sendkeys (Allinfo.emailpassword); WaitTime (3000); //Get the Code Entry box node and verify that the password is valid and password strength before entering the verification codeWebelement Emailimgvcode = driver.findelement (By.cssselector ("[Name=imgvcode]")); Emailimgvcode.click (); WaitTime (3000); //Get the Password check information node and determine when it exists and whether the information is "Password strength: High"Webelement Checkpassword = driver.findelement (By.cssselector ("[Class=password3]")); if(Checkpassword.isdisplayed () && "Password strength: High". Equals (Checkpassword.gettext ())) { //after the password check is passed, get the authentication verification picture node and get the information of the node through the method.webelement img = driver.findelement (By.cssselector ("[Id=capcha]")); System.out.println ("Verify that the hight of the picture is:" +img.getsize (). GetHeight ()); System.out.println ("Verify that the width of the picture is:" +img.getsize (). getwidth ()); System.out.println ("Verify that the SRC attribute value of the picture is:" + img.getattribute ("src")); WaitTime (3000); //Enter the verification code, selenium difficult to obtain the correct verification code in the real environment, if the test environment can be accessed by means of cookies. //Enter a verification code here at randomEmailimgvcode.sendkeys ("1234567890"); WaitTime (3000); //Gets the Submit button information, and some methods to get information about the nodeWebelement submit = Driver.findelement (By.cssselector ("[Class=subico]")); System.out.println (The text message for the submit button is: "+Submit.gettext ()); System.out.println (The class property value of the Submit button is: "+ submit.getattribute (" class ")); System.out.println (The Style property value of the Submit button is: "+ submit.getattribute (" style ")); System.out.println (The CSS property value for the Submit button is: "+ submit.getcssvalue (" float ")); System.out.println (The href attribute value of the Submit button is: "+ submit.getattribute (" href ")); Submit.submit (); WaitTime (5000); Driver.quit (); } Else{System.out.println ("Password check information is not displayed or password strength is low"); Driver.quit (); } } Else{System.out.println ("User name is not available"); Driver.quit (); } } Static Public voidWaitTime (intTime ) { Try{thread.sleep (time); } Catch(interruptedexception e) {//TODO auto-generated Catch blockE.printstacktrace (); } }}
Execution Result:
true 118 Verify that the SRC attribute value of the picture is: https://mail.sina.com.cn/cgi-bin/ createcode.php?t=1468141676float: left; the value of the CSS property for the Submit button is: the href attribute value of the left commit button is: javascript: void(0)
Original: http://www.cnblogs.com/moonpool/p/5658160.html
Selenium Test (Java)--element manipulation (v)