Automation Mac Build Chrome + Selenium Complete Web page Automation _ Automation

Source: Internet
Author: User

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.

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.