[英]When using Jmeter/ Blazemeter I get the error org.openqa.selenium.NoSuchElementException: Unable to locate element:
I load the script into blazemeter webdriver and upon running one user I get the following error: 我将脚本加载到blazemeter webdriver中,运行一个用户时出现以下错误:
sun.org.mozilla.javascript.WrappedException: Wrapped org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"loginForm_login_email"} Command duration or timeout: 6 milliseconds For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html Build info: version: '2.47.0', revision: '0e4837e94b1fad0db93e88cd972ed3e235a22892', time: '2015-07-29 15:58:41' System info: host: 'r-v3-56f99d3f9b3be-0-ccverdant-bulwark-278.internal', ip: '10.240.0.17', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-44-generic', java.version: '1.7.0_95' *** Element info: {Using=id, value=loginForm_login_email} Session ID: c5f12d1b-04f0-49a5-aeab-ab65a8c904e1 Driver info: org.openqa.selenium.firefox.FirefoxDriver Capabilities [{platform=LINUX, acceptSslCerts=true, javascriptEnabled=true, cssSelectorsEnabled=true, databaseEnabled=true, browserName=firefox, handlesAlerts=true, browserConnectionEnabled=true, nativeEvents=false, web
sun.org.mozilla.javascript.WrappedException:包装的org.openqa.selenium.NoSuchElementException:无法找到元素:{“ method”:“ id”,“ selector”:“ loginForm_login_email”}命令持续时间或超时:6毫秒文档说明关于此错误,请访问: http ://seleniumhq.org/exceptions/no_such_element.html构建信息:版本:“ 2.47.0”,修订版:“ 0e4837e94b1fad0db93e88cd972ed3e235a22892”,时间:“ 2015-07-29 15:58:41 '系统信息:主机:'r-v3-56f99d3f9b3be-0-ccverdant-bulwark-278.internal',ip:'10 .240.0.17',os.name:'Linux',os.arch:'amd64',os。版本:“ 3.13.0-44-generic”,java.version:“ 1.7.0_95” ***元素信息:{Using = id,value = loginForm_login_email}会话ID:c5f12d1b-04f0-49a5-aeab-ab65a8c904e1驱动程序信息:org.openqa.selenium.firefox.FirefoxDriver功能[{platform = LINUX,acceptSslCerts = true,javascriptEnabled = true,cssSelectorsEnabled = true,databaseEnabled = true,browserName = firefox,handlesAlerts = true,browserConnectionEnabled = true,nativeEvents = false,web StorageEnabled=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=26.0}] (#9) in at line number 9
StorageEnabled = true,rotatable = false,locationContextEnabled = true,applicationCacheEnabled = true,takesScreenshot = true,version = 26.0}](#9)在第9行
How do i fix this? 我该如何解决?
My code will work on occasion when I have higher "users" running through blazemeter but does not work when I have one "user" running through blazemeter . 当我有更高的“用户”通过blazemeter运行时,我的代码有时会工作,但当我有一个“用户”通过blazemeter运行时,我的代码将无法工作。
The code: 编码:
var pkg = JavaImporter(org.openqa.selenium);
var support_ui = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait);
var wait = new support_ui.WebDriverWait(WDS.browser, 5000);
WDS.sampleResult.sampleStart();
WDS.browser.manage().window().maximize();
WDS.browser.get("https://Website");
WDS.browser.findElement(pkg.By.id("loginForm_login_email")).click();
var username = WDS.browser.findElement(pkg.By.id('loginForm_login_email'));
username.sendKeys(["Generic"]);
WDS.browser.findElement(pkg.By.id("loginForm_password")).click();
var password = WDS.browser.findElement(pkg.By.id("loginForm_password"));
password.sendKeys(["Password1"]);
var button = WDS.browser.findElement(pkg.By.id("login-buttons-password"));
button.click();
WDS.sampleResult.sampleEnd();
And the element I am finding: 我发现的元素:
<input aria-invalid="false" id="loginForm_login_email" name="login_email"
placeholder="Username/Email" class="form-control"
data-validation-required-message="Please fill out this field."
required="" type="text">
As per Why can't I locate the element/NoSuchElementException work around? 按照我为什么找不到element / NoSuchElementException解决? chapter of The WebDriver Sampler: Your Top 10 Questions Answered guide:
WebDriver Sampler一章:您的十大问题解答指南:
A. There could be a number of reasons why you get this exception during the WebDriver Sampler execution:
答:在WebDriver Sampler执行期间,为什么有此异常可能有多种原因:
The element's locator is invalid
元素的定位器无效
The element belongs to another frame
元素属于另一个框架
The element is not available in DOM yet
该元素在DOM中尚不可用
I believe you're hitting point 3 so you need to "wait" for the element prior to attempt of working with it, something like: 我相信您到达了第3点,因此您需要在尝试使用该元素之前先“等待”它,例如:
var conditions = org.openqa.selenium.support.ui.ExpectedConditions
WDS.browser.get("https://Website");
wait.until(conditions.presenceOfElementLocated(pkg.By.id('loginForm_login_email')))
You may also want to increase WebDriverWait timeout as when server is under the load page rendering time might be more than 5 seconds 您可能还需要增加WebDriverWait超时,因为服务器处于加载页面下时,呈现时间可能会超过5秒
See Explicit Waits chapter of WebDriver: Advanced Usage documentation page for a little bit more detailed explanation of the approach. 有关此方法的详细说明,请参见WebDriver:高级用法文档页面的“ 显式等待”一章。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.