I'm trying to emulate https requests from mobile devices for client-side performance testing, using JSR223 + groovy, and the problem is that I couldn't perform in this way click on "Accept All Cookies" span element on page.
Response:
Response message:javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: ExpectedConditions for class: Script7
In 'desctop' part of script, xpath (implemented via WebDriver sampler) and click on this "Accept All Cookies" span element works 100% correctly - and by this reason I know, that xpath is correct.
Could you please take a look at the problem and share your thought and any tips, where could be the reason of problem in JSR223 and how is possible to solve it?
Code is here:
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();
How can I implement the same action when emulating mobile devices on client-side using JSR223?