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