java + selenium - WebElement 命令

What is WebElement? :


First, WebElement is a combination of the word, that is, open web + element, which translates elements (objects) on the web page. What is it that web page, HTMl find out?

Html immediately after learning did not take long, I am sure you are not familiar with html syntax of a pair of angle brackets of content, that this angle brackets, that is, we needed to automate the capture of UI Element.

 

Webelement interface methods acquaintance
Eclipse by object name. Method name to call up all Web Element methods

 

 Getting to know the relevant methods Web Element connectors on the front, we could start by the first chapter to the findElement method WebDriver to get to the Element object said.

 

After obtaining to the Element, we can officially start the next learning method related to the Web Element interface.

 

 

 

Clear () method
clear (): void-- If the element is a type of text elements, then we can empty the contents of the text by this method.

 

Syntax: element.clrea ();

 

 

The SendKeys () method
sendkeys (): void-- element values to populate

 

Syntax: ele.sendKeys ( "value");

 

 

 

Click () method
click (): void-- This method simulates user clicks on the UI elements in the page action

Syntax: ele.click ();

 

 

 

 

isDisplayed () method
isDisplayed (): Boolean-- the method used to determine whether the elements on the page currently displayed

 

Syntax: ele.isDisplayed ();

 

 

 

 

method isEnabled ()
isEnabled (): boolean-- interface elements used to determine whether it is available, returns a boolean value. Returns a boolean value, may be considered in conjunction with the use statement Analyzing

 

Syntax: ele.isEnabled ();

 

 

 

isSelected () method
isSelected (): boolean-- to the interface is determined by an element which is selected whether

 

Syntax: ele.isSelected ();

 

 

 

submit () method
submit (): boolean-- Submit form to form by this method. html we learn form the form is submitted by the submit method, so for the form element, selenium is also provided a method we submit that the submitted data.

 

Syntax: ele.submit (); the premise of using this method is that element method call is the type of form element

 

 

 

getText () method
gettext (): String-- get the text content of the element. What is the text? Html is the angle brackets to the middle of writings

Syntax: ele.getText ();

 

 

 

getTagName () method
getTagName (): String - tagname i.e. html tag type of the tag, such as a, input, table and the like.

 

Syntax: ele.getTagName ();

 

 

 

getCssValue () method
getCssValue (): String-- css style Gets the value of the element, the reference element within a string type style name, such as background color, length, width, etc.

 

Syntax: ele.getCssValue ( "heigth");

 

 

 

getAttribute () method
getAttribute (): String-- Gets the value of the element property, the content reference for an attribute name element

 

Syntax: ele.getAttribute ( "type");

 

 

 

getSize () method
getSize (): Dimension-- acquired size of the element, i.e. length and width of element

 

Syntax: ele.getSize ();

 

 

 

getLocation () method of
the element on the page layout will have a position, that is what we call the horizontal and vertical coordinates, the coordinate position can also be determined by one element to

getLocation (): Point-- obtain coordinate position of the element on the page

 

Syntax: ele.getLocation ();

 

 ========================================================================

 

 

 

Package rjcs; 

Import java.util.List; 

Import org.openqa.selenium.firefox.FirefoxDriver;
 Import org.openqa.selenium.By;
 Import org.openqa.selenium.WebElement;
 Import org.testng.annotations.Test; 

Import COM .thoughtworks.selenium.SeleneseTestNgHelper; 

public  class WebElement 
{ 
    
    public  static  void main (String [] args) 
    
    { 
         System.setProperty ( "webdriver.firefox.bin", "C: \\ Program Files (the x86) \\ \\ the Mozilla Firefox firefox.exe ");     // set the installation path Firefox, preventing system can not find 
            
         FirefoxDriver driver= New new FirefoxDriver ();         // initialize FireFox browser instance, and open the browser 
         
        the try 
        { 
             driver.manage () window () Maximize ();..          // maximized window 
             
             the Thread.sleep ( 5000 );         
             
             driver.manage ( .) .window () the maximize ();          // maximize the window 
             
             Thread.sleep ( 5000 ); 
        
             driver.get ( "https://www.baidu.com");                     // open a URL, a method              
        
             Thread.sleep ( 5000 ); 
             
             
             WebElement CS = driver.findElement (By.id ( "kW"));
             cs.clear();
             cs.sendKeys("中国");
             
             WebElement dj = driver.findElementById("su");
             dj.click();
             

             Thread.sleep(5000);            
             
        }catch (Exception e) 
        {
            e.printStackTrace();
        }finally 
        {
            driver.quit();
        
         }
   }
    

}

Guess you like

Origin www.cnblogs.com/xiaobaibailongma/p/12214529.html