Java Selenium ChromeDriver程序在我的计算机上运行很快,但在其他计算机上运行缓慢

时间:2019-07-08 19:47:39

标签: java eclipse selenium selenium-webdriver selenium-chromedriver

我编写了一个Java程序,该程序利用Selenium来控制Google Chrome。如果我在计算机上运行该程序,则该程序将以合理的速度正常运行。但是,当我将此文件导出到另一台计算机(.jar或.exe)时,它仍然可以正常运行,但运行速度非常慢。具体来说,在文本框中编写并单击按钮似乎要花费更长的时间。

在整个程序中,我调用此方法以确保在执行操作之前文本框/标签将存在:

/**
 * This function allows the driver to wait until the element is visible before interacting with it 
 * @param driver - The driver that is being used
 * @param webElement - A string describing the xpath of the element to wait for 
 * @param seconds - The maximum number of seconds that the driver is willing to wait
 * @return - The WebElement after it has appeared on the page 
 */
public static WebElement waitForElementToBeVisible(WebDriver driver, String webElement, int seconds) {
    try {
        WebDriverWait wait = new WebDriverWait(driver, seconds);

        WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(webElement))); 

        return element;
    } 
    catch (TimeoutException e){
        return null; 
    }

}

而且,我调用此方法以确保在调用操作之前按钮是可单击的:

/**
 * This function allows the driver to wait until the element is clickable before interacting with it 
 * @param driver - The driver that is being used 
 * @param webElement - A string describing the xpath of the element to wait for 
 * @param seconds - The maximum number of seconds that the driver is willing to wait
 * @return - The WebElement after it has appeared on the page 
 */
public static WebElement waitForElementToBeClickable(WebDriver driver, String webElement, int seconds) {
    WebDriverWait wait = new WebDriverWait(driver, seconds); 

    WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath(webElement)));

    return element; 
}

根据我的研究,我试图以多种方式解决该问题。首先,我尝试通过Google Chrome调整代理设置,但是两台机器上的设置相同。其次,我尝试以编程方式设置代理设置,但这也没有加快程序的速度。最后,我尝试减少传递给上述方法的时间。不幸的是,这也没有加快程序的速度。有谁知道如何在每台机器上具有类似的Java Selenium程序性能?

在此先感谢您提供的任何帮助。

0 个答案:

没有答案