等待元素显示在 Web 驱动程序采样器中不起作用
Wait for element to display is not working in web driver sampler
我正在使用 webdriver sampler 进行测试,我正在等待 table 出现在我的页面上,但它不起作用,
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 定位器没问题,
CSS Locator
你能试试这个吗,
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();
我正在使用 webdriver sampler 进行测试,我正在等待 table 出现在我的页面上,但它不起作用,
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 定位器没问题,
CSS Locator
你能试试这个吗,
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();