Selenium Java MAVEN automation Test (ii) page element acquisition and manipulation

Source: Internet
Author: User
Tags tag name xpath

In the first section, we have successfully opened the page, but the automated test necessarily contains the form's fill-in and button clicks. So in the second chapter I take the blog garden as an example, complete the button click, Form Fill

or code-based, first on the code:

 PackageCom.ryan;Importorg.openqa.selenium.By;ImportOrg.openqa.selenium.WebDriver;Importorg.openqa.selenium.WebElement;ImportOrg.openqa.selenium.chrome.ChromeDriver; Public classDemo { Public Static voidMain (string[] args) {System.setproperty ("Webdriver.chrome.driver", ". \\tools\\chromedriver.exe"); Webdriver Driver=NewChromedriver (); Driver.get ("HTTP://WWW.CNBLOGS.COM/RYAN255/"); System.out.println (Driver.gettitle ());

Get buttons on page webelement button= Driver.findelement (By.cssselector ("#blog_nav_admin"));
Click the button Button.Click ();
Get the input box on the page webelement input1= Driver.findelement (By.cssselector ("#input1"));
Clean the contents of the input box input1.clear ();
Input Input1.sendkeys ("Ryan255");
Thread.Sleep (5000); Driver.quit (); }}

As the above note shows, the code here adds the action to get the page element, click the button, and enter the form.

the Selenium offers 8 positioning methods:
    • Id
    • Name
    • Class name
    • Tag name
    • Link text
    • Partial link text
    • Xpath
    • CSS Selector
here are the 8 ways to locate in the code:
    • Findelement (By.id ())
    • Findelement (By.name ())
    • Findelement (By.classname ())
    • Findelement (By.tagname ())
    • Findelement (By.linktext ())
    • Findelement (By.partiallinktext ())
    • Findelement (By.xpath ())
    • Findelement (By.cssselector ())

Selenium Java MAVEN automation Test (ii) page element acquisition and manipulation

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.