jmeter - 等待元素显示在 Web 驱动程序采样器中不起作用
问题描述
我正在使用 webdriver 采样器进行测试,我正在等待一个表格出现在我的页面上,但该表格不起作用,
var driver = JavaImporter(org.openqa.selenium); //WebDriver classes
var driver_ui = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait); //WebDriver classes
var start = new Date().getTime()
WDS.sampleResult.sampleStart();
WDS.sampleResult.getLatency();
WDS.browser.get("https://<some_url>/mrlb/f4d7f910-03bf-4c6f-93aa-0d47d7ec5afd");
var attempt = 1 ;
while (new Date().getTime() - start < 5000) {
try{
if (WDS.browser.findElement(driver.By.className('.dataTables_wrapper.form-inline.dt-bootstrap.no-footer')).isDisplayed()) {
WDS.log.info('Table is displayed')
break;
}
}
catch(err){
if (attempt < 10) {
WDS.log.info('Attempt # ' + attempt + ', Element not found');
java.lang.Thread.sleep(2000)
attempt++
WDS.log.info('Current Value of Attemp # ' + attempt);
}
}
}
WDS.sampleResult.sampleEnd();
也试过
wait.until(driver.ExpectedConditions.elementToBeClickable(pkg.By.className('.dataTables_wrapper.form-inline.dt-bootstrap.no-footer')));
WDS.log.info("Table displayed");
break;
还检查了css定位器很好,
解决方案
你能试试这个吗
var driver = JavaImporter(org.openqa.selenium); //WebDriver classes
var driver_ui = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait); //WebDriver classes
var start = new Date().getTime()
var conditions = org.openqa.selenium.support.ui.ExpectedConditions
var wait=new driver_ui.WebDriverWait(WDS.browser, 20)
var exception = null
WDS.sampleResult.sampleStart();
WDS.sampleResult.getLatency();
WDS.browser.get("https://<url>");
try {
wait.until(conditions.presenceOfElementLocated(driver.By.className('.dataTables_wrapper.form-inline.dt-bootstrap.no-footer')))
WDS.sampleResult.setSuccessful(true);
}
catch (error){
exception = error;
WDS.sampleResult.setSuccessful(false);
}
WDS.sampleResult.sampleEnd();
推荐阅读
- javascript - 如何更改 CATCH 块内的页面(Node.js 和 Express)?
- python - Scrapy:无法从 xpath 获取数据
- arduino - LED 在亮度控制时随机关闭
- django-models - 我需要有人将 blenderbot-3B 推送到我的拥抱脸仓库
- swift - 我的 SwiftUI 代码导致一个大的 ol 空白窗口
- java - 转换为 ascii 并返回后,Java 字节数组大小翻倍
- html - 将css导入另一个css文件的原因?
- google-colaboratory - Google Colab Pro+ 断开连接并停止执行,只允许一个会话
- css - 如何禁用 Mattab 点击事件 MatBlazor
- sql-server - 有没有办法为关系数据库中的文本重字段保存版本控制?