【发布时间】:2019-07-20 21:08:06
【问题描述】:
我在 Jmeter 中使用 WebDriverSampler 进行了一些测试,这些测试可以与 chromedriver 一起正常工作。它是一个 selenium 脚本,可以打开一个网页并检查它是否包含一系列元素。在我尝试使用 chromedriver headless 选项之前,一切正常。
在这种情况下,我得到异常“预期条件失败:等待存在的元素位于:By.xpath:...”,就好像该元素不存在尚未加载一样。我不知道会发生什么,因为如果我停止使用 headless 选项,如果一切正常并找到真正存在的元素。
这是一个使用的代码示例(它可以在没有 headless 选项的情况下工作):
var wait = new support_ui.WebDriverWait(WDS.browser, 30);
var conditions = org.openqa.selenium.support.ui.ExpectedConditions
WDS.sampleResult.sampleStart();
WDS.sampleResult.getLatency();
WDS.browser.get('http://mi-app/');
try{
wait.until(conditions.presenceOfElementLocated(pkg.By.xpath('/ruta_de elemento_existente')));
WDS.log.info('OK')
}catch(e){
WDS.sampleResult.setSuccessful(false);
WDS.sampleResult.setResponseMessage('Fail');
WDS.log.error(e.message)
}
try{
wait.until(conditions.presenceOfElementLocated(pkg.By.xpath('/ruta_de elemento2_existente')));
WDS.log.info('OK2')
}catch(e){
WDS.sampleResult.setSuccessful(false);
WDS.sampleResult.setResponseMessage('Fail2');
WDS.log.error(e.message)
}
WDS.sampleResult.sampleEnd();
我希望有人可以帮助我解决这个问题,因为我需要使用无头选项。非常感谢您的宝贵时间。
【问题讨论】:
标签: selenium-webdriver jmeter selenium-chromedriver jmeter-plugins google-chrome-headless