Background to implement environment description preparation how to write code
background
Through selenium can complete the operation of the web automatically, freeing your hands. Implement Environment Introduction
Mac
Chrome version 64.0.3282.140 (official version)
Selenium-java 3.8.1
Chrome Selenium driver 2.35 prep work
First you need to download the chrome or other browser driver. Here's a case of chrome.
Here is the image of Taobao. https://npm.taobao.org/mirrors/chromedriver/
Download the 2.35 version of the selenium Mac driver on the Taobao image.
Prevent in the engineering directory or other places. Here I put in the engineering directory.
Add selenium configuration to the Pom file.
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.8.1</version>
</ Dependency>
</dependencies>
Write Java code as follows.
Import Org.openqa.selenium.By;
Import Org.openqa.selenium.chrome.ChromeDriver;
/** *
@author Arthur
* @Date 2018/2/8
* @Decription: * * Public
class Seleniummaintest {
public static void Main (string[] args) {
system.setproperty ("Webdriver.chrome.driver", System.getproperty ("User.dir") + "/chromedriver");
Chromedriver Driver = new Chromedriver ();
Driver.get ("https://www.taobao.com/");
Driver.findelement (By.id ("Q")). Click ();
Driver.findelement (By.id ("Q")). Clear ();
Driver.findelement (By.id ("Q")). SendKeys ("Java Concurrency Programming");
Driver.findelement (By.cssselector ("BUTTON.BTN-SEARCH.TB-BG")). Click ();
}
The effect is to open Taobao, and automatically search "Java concurrent programming."
How to write code
Some friends will ask: without the foreground programming experience, this code how to write it. Here I have a tool to recommend everyone. The following figure.
Through the screen Recording tool, recording the entire web operation process, playback attempts, no problem, you can export the code.
You can export Java, Python, and so on.
Of course, for the receptionist more familiar friends, you can directly freehand code.
Add that you can use Google browser to get directly to the page elements of XPath.
Also recommend a blog, a more detailed record of the selenium element positioning method. Https://www.cnblogs.com/TankXiao/p/5222238.html.