Chrome web crawling for Java automated testing

Record a fun little plug-in, you can use it to get an element on the web page, and then get its value, but you need to understand the front-end technology, and you also need a chrome gadget. The tool is placed in my shared file, called chromedriver plugin

  1. pom dependencies
<dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-server</artifactId>
            <version>3.141.59</version>
        </dependency>

2. Execute code

 public static void main(String[] args) {
    
    

        System.setProperty("webdriver.chrome.driver", "D:\\mywork\\xncs\\software-main\\software-main\\chromedriver\\chromedriver.exe");
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--headless");
        WebDriver driver = new ChromeDriver(options);
        WebDriverWait wait = new WebDriverWait(driver, 10);
        driver.get("http://172.24.1.222:9002/perfreport/1088/10881691742703973/");
        wait.until(webDriver -> ((JavascriptExecutor) webDriver)
                .executeScript("return document.readyState").equals("complete"));

        String error = driver.findElement(By.xpath("//table[@id=\"statisticsTable\"]/tbody[1]/tr/td[4]")).getText();

        System.out.println("error: " + error);

        driver.quit();

    }

Guess you like

Origin blog.csdn.net/weixin_45933454/article/details/132235852