【问题标题】:JMeter Groovy - WebDriver Sampler script failed with Response Code 500JMeter Groovy - WebDriver Sampler 脚本失败,响应代码为 500
【发布时间】:2021-02-04 15:43:43
【问题描述】:

我不确定为什么在我的脚本上保持失败并显示响应代码 500。请是我的示例代码和错误消息。请多多指教。非常感谢。

错误信息:

timeStamp,elapsed,label,responseCode,responseMessage,threadName,dataType,success,failureMessage,bytes,sentBytes,grpThreads,allThreads,URL,Latency,IdleTime,Connect
1612415604534,36638,jp@gc - WebDriver Sampler,500,"javax.script.ScriptException: org.openqa.selenium.ElementNotInteractableException: element not interactable
(Session info: chrome=88.0.4324.146)

示例代码:

import org.openqa.selenium.*;
import org.openqa.selenium.support.ui.*;
WDS.sampleResult.sampleStart();
WDS.browser.get("https://uat-testing.com/");
sleep(10000);
WDS.browser.findElement(org.openqa.selenium.By.xpath("//input[@type='text']")).sendKeys("xxxx@testing.com");
WDS.browser.findElement(org.openqa.selenium.By.xpath("//input[@type='password']")).clear();
WDS.browser.findElement(org.openqa.selenium.By.xpath("//input[@type='password']")).sendKeys("xxx@xxxx");
WDS.browser.findElement(org.openqa.selenium.By.xpath("//button/span")).click();
sleep(20000);
WDS.browser.findElement(org.openqa.selenium.By.xpath("//div[10]/li/span")).click();
WDS.browser.findElement(org.openqa.selenium.By.xpath("//div[16]/li/span")).click();
WDS.browser.findElement(org.openqa.selenium.By.xpath("//div[3]/li/span")).click();
WDS.browser.findElement(org.openqa.selenium.By.xpath("//div[5]/div/div/div")).click();
WDS.browser.findElement(org.openqa.selenium.By.xpath("//ul[contains(@id,'dropdown-menu-')]/li")).click();
WDS.browser.findElement(org.openqa.selenium.By.xpath("(//button[contains(@type,'button')])")).click();
sleep(30000);
WDS.sampleResult.sampleEnd();

【问题讨论】:

    标签: selenium-webdriver groovy jmeter


    【解决方案1】:

    ElementNotInteractableException 表示您尝试使用的元素不能被 WebDriver 使用

    抛出表示虽然一个元素存在于 DOM 上,但它并不处于可以交互的状态。

    很可能它被其他 DOM 元素“覆盖”了,因此选项位于:

    • 使用Explicit Wait“等待”直到可以访问元素(顺便说一下,您还应该考虑将“睡眠”替换为显式等待,因为这是一种性能反模式)
    • 您可能希望与悬停它的元素进行交互,而不是尝试使用特定的此元素,以便将定位器更改为另一个定位器
    • 最后,您可以使用JavaScript Executor 来通过JavaScript 执行“点击”

    有关 WebDriver Sampler 的更多信息:The WebDriver Sampler: Your Top 10 Questions Answered

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多