javascript - 使用 Jmeter/Blazemeter 时出现错误 org.openqa.selenium.NoSuchElementException : Unable to locate element:

标签 javascript webdriver jmeter blazemeter

我将脚本加载到 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-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

我该如何解决这个问题?

当我有更高级别的“用户”通过 blazemeter 运行时,我的代码有时会起作用,但当我有一个“用户”通过 blazemeter 运行时,我的代码就不起作用了。 p>

代码:

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();

我找到的元素:

<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">

最佳答案

根据 为什么我无法定位元素/NoSuchElementException 解决方法? 章节 The WebDriver Sampler: Your Top 10 Questions Answered指南:

A. There could be a number of reasons why you get this exception during the WebDriver Sampler execution:

  1. The element’s locator is invalid

  2. The element belongs to another frame

  3. The element is not available in DOM yet

我相信您已达到第 3 点,因此您需要在尝试使用该元素之前“等待”该元素,例如:

var conditions = org.openqa.selenium.support.ui.ExpectedConditions
WDS.browser.get("https://Website");
wait.until(conditions.presenceOfElementLocated(pkg.By.id('loginForm_login_email')))

您可能还想增加 WebDriverWait 超时,因为当服务器负载不足时页面呈现时间可能超过 5 秒

参见 Explicit Waits章节WebDriver: Advanced Usage有关该方法的更详细说明的文档页面。

关于javascript - 使用 Jmeter/Blazemeter 时出现错误 org.openqa.selenium.NoSuchElementException : Unable to locate element:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36271736/

相关文章:

javascript - getJson 使用 jQuery 加载特定数据不起作用

python - 告诉我为什么这不会以超时错误结束(selenium 2 webdriver)?

jmeter - Jmeter beanshell类notfounderror

parameters - 如何让jMeter http请求采样器生成参数?

ubuntu - 当我进行 Jmeter 压力测试时,是什么阻止了我的 IP 地址?

javascript - 按对象属性对 JavaScript 数组进行排序

javascript - Input Type Range 控件在 IE 中显示为文本框

javascript - 如何在jsp中使用javascript动态添加文本框

java - Selenium: JUnit4: WebDriver: IE: 使用 IE 时出现 NoSuchElementException

c# - 在多个驱动程序上运行 WebDriver NUnit 测试