当前位置: 首页 > 知识库问答 >
问题:

JMeter-Mobile devices请求使用JSR223&groovy进行仿真-没有这样的属性:ExpectedConditions错误

闻华容
2023-03-14

响应消息:javax.script.scriptException:javax.script.scriptException:groovy.lang.MissingPropertyException:没有这样的属性:类的ExpectedConditions:Script7

在脚本的“desctop”部分,xpath(通过WebDriver sampler实现)并单击这个“Accept All Cookies”span元素可以100%正确地工作--因此我知道,xpath是正确的。

你能看看这个问题并分享你的想法和任何建议吗?在JSR223中问题的原因在哪里?如何解决它?

import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.util.concurrent.TimeUnit;

System.setProperty("webdriver.chrome.driver", "${webdriver_path}");

Map<String, Object> deviceMetrics = new HashMap<>();
deviceMetrics.put("width", ${width});
deviceMetrics.put("height", ${height});
deviceMetrics.put("pixelRatio", ${pixelRatio});
Map<String, Object> mobileEmulation = new HashMap<>();
mobileEmulation.put("deviceMetrics", deviceMetrics);
mobileEmulation.put("userAgent", "${userAgent}");
Map<String, Object> chromeOptions = new HashMap<>();
chromeOptions.put("mobileEmulation", mobileEmulation);
//DesiredCapabilities capabilities = DesiredCapabilities.chrome();
//capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);

ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("mobileEmulation", mobileEmulation);
ChromeDriver driver = new ChromeDriver(options);
driver.get("https://${HOST_MAIN}");

WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[contains(text(), 'Accept All Cookies')]")));
driver.findElement(By.xpath("//span[contains(text(), 'Accept All Cookies')]")).click();

//this way doesn't work too:
//WebDriverWait(driver, 20).until(EC.element_to_be_clickable(By.xpath("//span[contains(text(), 'Accept All Cookies')]"))).click();

log.info(driver.getTitle());
driver.quit();

当使用JSR223在客户端模拟移动设备时,如何实现相同的操作?

共有1个答案

鄢子平
2023-03-14

在我看来,这是一个错别字或复制粘贴问题,您需要更改如下:

import org.openqa.selenium.support.ui.ExpectedCondition;

到这一行:

import org.openqa.selenium.support.ui.ExpectedConditions;

因为它必须是完全限定和正确的ExpectedConditions类名

    null
 类似资料: