JMeter WebDriver采样器报错:MissingPropertyException求助
原代码:
import org.openqa.selenium.By; import org.openqa.selenium.support.ui.WebDriverWait; import org.openqa.selenium.chrome.ChromeDriverService; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; import static org.openqa.selenium.support.ui.ExpectedConditions.* import org.openqa.selenium.support.ui.*; import openqa.selenium.OutputType.*; // 1. Go to a page with a form WDS.browser.get('http://mobile.yellow.com.au') // 2. Enter characters into the text input field WDS.browser.findElement(By.id('clue'))sendKeys('tyres')
报错信息:
javax.script.ScriptException: javax.script.ScriptException:
groovy.lang.MissingPropertyException: No such property: org for class:
Script32 at
org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:158)
at
java.scripting/javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:262)
at
com.googlecode.jmeter.plugins.webdriver.sampler.WebDriverSampler.sample(WebDriverSampler.java:99)
at
org.apache.jmeter.threads.JMeterThread.doSampling(JMeterThread.java:651)
at
org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:570)
at
org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:501)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:268)
at java.base/java.lang.Thread.run(Thread.java:1589)
问题分析与修复:
- 导入语句错误:
import openqa.selenium.OutputType.*;包名缺失前缀org.,正确写法为import org.openqa.selenium.OutputType; - 语法错误:
WDS.browser.findElement(By.id('clue'))sendKeys('tyres')中findElement方法调用后缺少.,正确写法为WDS.browser.findElement(By.id('clue')).sendKeys('tyres') - 冗余导入清理:JMeter WebDriver采样器已通过
WDS对象封装了浏览器操作,ChromeDriverService、RemoteWebDriver等导入可删除,避免不必要的依赖
修复后的代码:
import org.openqa.selenium.By; import org.openqa.selenium.support.ui.WebDriverWait; import static org.openqa.selenium.support.ui.ExpectedConditions.*; import org.openqa.selenium.support.ui.*; import org.openqa.selenium.OutputType; // 1. 打开带表单的页面 WDS.browser.get('http://mobile.yellow.com.au') // 2. 在文本输入框中输入内容 WDS.browser.findElement(By.id('clue')).sendKeys('tyres')
内容的提问来源于stack exchange,提问作者Bijayananda Patra

