kendoMultiSelect: 如何使用Java Selenium选择多个值?

huangapple go评论72阅读模式
英文:

kendoMultiSelect: Java Selenium How to select multiple values?

问题

我正尝试从 kendoMultiSelect 中选择多个值,但无法使用 Selenium 方法与其进行交互。我猜我需要使用 JavaScript 执行函数。我应该使用哪个函数?

英文:

I am trying to select multiple values from a kendoMultiSelect, I can't interact it with the Selenium methods. I guess i need to use javascript execute function. What function should i use?

答案1

得分: 1

是的,执行 JavaScript 函数将是您最安全的选择。

在 Selenium 中使用它,您需要使用驱动程序的 JavascriptExecutor 接口。

// 在此处使用您现有的驱动程序
WebDriver driver = new FirefoxDriver();
// 通过强制类型转换获得 JavascriptExecutor 接口对象
JavascriptExecutor js = (JavascriptExecutor) driver;
// 使用您的 JS 代码调用 executeAsyncScript() 方法
js.executeAsyncScript("kendoMultiSelect.value([\"Value 1\",\"Value 2\"]);");

kendoMultiSelect 变量是一个 JS 变量,用于引用您的 select 实例。

英文:

Yes javascript execute function will be your safest bet.

To use it in selenium you need to use the JavascriptExecutor interface of a driver.

// Use your existing driver here
WebDriver driver= new FirefoxDriver();	
//JavascriptExecutor interface object by casting	
JavascriptExecutor js = (JavascriptExecutor)driver;
//executeAsyncScript() method with your JS		
js.executeAsyncScript("kendoMultiSelect.value(["Value 1","Value 2"]);");

The kendoMultiSelect variable is a JS variable that references your instance of the select.

huangapple
  • 本文由 发表于 2020年7月24日 16:47:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/63070132.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定