Java 无头铬合金的性能问题

Java 无头铬合金的性能问题,java,selenium,xpath,Java,Selenium,Xpath,只有在启用无头模式时,我的脚本才会失败。请建议我的方式,我应该看什么,而编码 由于TimedOut,我的大多数脚本都失败了。 有什么我应该特别寻找的定位器吗?我相信css在这种情况下帮不了我。还有其他与定位器相关的东西吗? 在持续集成服务器中,执行速度非常慢。超时秒的限制固定为50。这对我不起作用,甚至对100人也不起作用。请建议我如何处理当我被限制使用最多100秒超时,它遇到异常,因为它需要比这更多的秒。 只有在启用headless时,我才会收到一些例外情况 1. WebDriverExcep

只有在启用无头模式时,我的脚本才会失败。请建议我的方式,我应该看什么,而编码

由于TimedOut,我的大多数脚本都失败了。 有什么我应该特别寻找的定位器吗?我相信css在这种情况下帮不了我。还有其他与定位器相关的东西吗? 在持续集成服务器中,执行速度非常慢。超时秒的限制固定为50。这对我不起作用,甚至对100人也不起作用。请建议我如何处理当我被限制使用最多100秒超时,它遇到异常,因为它需要比这更多的秒。 只有在启用headless时,我才会收到一些例外情况

1. WebDriverException: unknown error: Element <input type="radio" class="wizard-input" name="5a68a4c173bb-TOTAL-1" id="5a68a4c173bb-TOTAL-1" value="1"> is not clickable at point (496, 551). Other element would receive the click: <div class="navigation-bar">...</div>
试图应用马塞尔建议的条件。据说它甚至超过了100秒

下面是一些我的代码示例

public void clickForwardButton(){
    WaitTillElementToBeClickable("xpath", LoginData.Forward);
    ScrollAndClickOnElement("xpath", LoginData.Forward);
} //The error seems to be like it wont scroll properly and hence I receive element not found exception

protected void WaitTillElementToBeClickable(String locatorType, String locatorValue) {
try {
  WebDriverWait wait = new WebDriverWait(driver, TIME_OUT_IN_SECONDS);
  if (locatorType.equalsIgnoreCase("cssSelector")) {
    wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(locatorValue)));
  } else if (locatorType.equalsIgnoreCase("xpath")) {
    wait.until(ExpectedConditions.elementToBeClickable(By.xpath(locatorValue)));
  } else if (locatorType.equalsIgnoreCase("id")) {
    wait.until(ExpectedConditions.elementToBeClickable(By.id(locatorValue)));
  }
} catch (Exception e) {
  logger.error("Webdriver Locator Error" + e);
}
}

如果您没有使用WebDriverWait,请尝试一下

int seconds = 5;
WebDriverWait wait = new WebDriverWait(driver, seconds);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("yourID")));
您必须导入OpenQA.Selenium.Support.UI才能使用WebDriverWait

编辑

由于WebDriverWait方法不提供解决方案,请尝试在ChromeOptions中添加其他参数以设置窗口大小。由于默认的无头窗口大小可能比您的无头窗口大小小得多,因此值得一试。设置更大的窗口大小的另一个好处是减少了滚动的需要

ChromeOptions options = new ChromeOptions();
options.addArgument("headless");
options.addArgument("window-size=1920,1080");

// or

options.addArguments("headless", "window-size=1920,1080");

你能分享你失败的代码块以及相关的HTML和错误堆栈跟踪吗?@Debanjan-我用几个例子更新了我的问题。请检查。谢谢Debanjan,我现在很清楚如何通过理解给定的链接来修复我的代码。好消息!!!如果有任何答案对你有用,请投票。谢谢马塞尔。我已经考虑过这一点。在持续集成服务器中,执行速度非常慢。超时秒的限制固定为50。这对我不起作用,甚至对100人也不起作用。请建议我如何处理当我被限制为只使用100秒超时,它会遇到异常,因为它需要比这更多的秒。这真的太长了,我已经用额外的信息更新了我的答案,这真是太好了。它成功地解决了我上面的第一个异常WebDriver异常。太棒了,很高兴它有帮助!
ChromeOptions options = new ChromeOptions();
options.addArgument("headless");
options.addArgument("window-size=1920,1080");

// or

options.addArguments("headless", "window-size=1920,1080");