Selenium 鼠标点击事件踩坑

定位标签后,点击一定要设置延时,不然点击执行太快js文件来不及加载导致没有点击反应

最开始我以为等待元素出来即可,结果一直点击没反应。。

public class SelTest {
    public static void main(String[] args) throws InterruptedException, IOException {
        System.setProperty("webdriver.edge.driver", "D:/下载/msedgedriver.exe");
        WebDriver driver = new EdgeDriver();
        driver.get("http://app.xunjietupian.com/");
        //裁剪图片
        driver.findElement(By.xpath("/html/body/div/div/section[2]/div/div/a/li")).click();
        //显式等待, 针对某个元素等待
        WebDriverWait wait = new WebDriverWait(driver, 10, 1);
        WebElement elem = wait.until(new ExpectedCondition<WebElement>() {
            @NullableDecl
            public WebElement apply(@NullableDecl WebDriver webDriver) {
                assert webDriver != null;
                return webDriver.findElement(By.xpath("//*[@id='app']/div[1]/div[3]/div/section[2]/div[2]"));
            }
        });
        System.out.println("elem.getText() = " + elem.getText());

        //Actions actions = new Actions(driver);
        Thread.sleep(2000);
        //actions.click(elem).perform();
        elem.click();
        Thread.sleep(2000);
        Runtime.getRuntime().exec("src/main/resources/uploadPic.exe");
        Thread.sleep(10000);
        driver.quit();

    }
}

你可能感兴趣的:(踩坑)