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:
1 Packagecom.test.elementoperation;2 3 Importorg.openqa.selenium.By;4 ImportOrg.openqa.selenium.WebDriver;5 Importorg.openqa.selenium.WebElement;6 ImportOrg.openqa.selenium.firefox.FirefoxDriver;7 8 Public classElementoperationemail {9 Ten Public Static voidMain (string[] args) { One AWebdriver Driver =Newfirefoxdriver (); - -Driver.get ("https://mail.sina.com.cn/register/regmail.php"); the driver.manage (). window (). Maximize (); - - //get the Email Name input box node and enter a name -Webelement emailname = driver.findelement (By.cssselector ("[Name=email]")); + emailname.clear (); Emailname.click (); Emailname.sendkeys (allinfo.emailname); A at //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 browser -Webelement Emailpassword = driver.findelement (By.cssselector ("[NAME=PSW]")); -Emailpassword.click ();//Click the Password box to make the email name verification information appear -WaitTime (3000); - //get the email name Verification information node and determine if the information is "left arrow" -Webelement CheckName =Driver in. 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 method toSystem.out.println ("Verify that the user name information exists:" +checkname.isdisplayed ()+ "The information of the comparison result is:" +checkcontent); + //get to the information and start judging and make a different branch - if("Left Arrow". Equals (checkcontent)) { the //Enter the password after confirming the name is correct * Emailpassword.sendkeys (Allinfo.emailpassword); $WaitTime (3000);Panax Notoginseng - //Get the Code Entry box node and verify that the password is valid and password strength before entering the verification code theWebelement Emailimgvcode = driver.findelement (By.cssselector ("[Name=imgvcode]")); + Emailimgvcode.click (); AWaitTime (3000); the //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 the hight of the picture is:" + img.getsize (). GetHeight ()); theSystem.out.println ("Verify 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"));WuyiWaitTime (3000); the - //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. Wu //Enter a verification code here at random -Emailimgvcode.sendkeys ("1234567890"); AboutWaitTime (3000); $ - //Gets the Submit button information, and some methods to get information about the node -Webelement submit = Driver.findelement (By.cssselector ("[Class=subico]")); -SYSTEM.OUT.PRINTLN (the text message for the submit button is: "+Submit.gettext ()); ASYSTEM.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 "))); theSystem.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 (); theWaitTime (5000); the the driver.quit (); the -}Else { inSystem.out.println ("Password check information is not displayed or password strength is low"); the driver.quit (); the } About the}Else { theSystem.out.println ("User name is not available"); the driver.quit (); + } - the }Bayi the Static Public voidWaitTime (intTime ) { the - Try { - Thread.Sleep (time); the}Catch(interruptedexception e) { the //TODO auto-generated Catch block the e.printstacktrace (); the } - } the}
Execution results
true 2 verifies that the hight of the picture is: 343 Verify that the width of the picture is: 1184 validates that the SRC attribute value of the picture is: Https:// mail.sina.com.cn/cgi-bin/createcode.php?t=1468141676 5 6 float : Left; 8 9 the href attribute value of the submit button is: Javascript:void (0)
Here is the page and the information you see Using Firebug
Selenium Test (Java)--element manipulation