Reputation: 11
I load the script into blazemeter webdriver and upon running one user I get the following error:
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-c.c.verdant-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, webStorageEnabled=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=26.0}] (#9) in at line number 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.
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">
Upvotes: 1
Views: 1424
Reputation: 168002
As per Why can’t I locate the element/NoSuchElementException work around? chapter of The WebDriver Sampler: Your Top 10 Questions Answered guide:
A. There could be a number of reasons why you get this exception during the WebDriver Sampler execution:
The element’s locator is invalid
The element belongs to another frame
The element is not available in DOM yet
I believe you're hitting point 3 so you need to "wait" for the element prior to attempt of working with it, something like:
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
See Explicit Waits chapter of WebDriver: Advanced Usage documentation page for a little bit more detailed explanation of the approach.
Upvotes: 2