JMeter Groovy-具有响应代码500的WebDriver采样器动态名称 [英] JMeter Groovy - WebDriver Sampler Dynamic Name with Response Code 500
问题描述
我已经厌倦了使用JMeter Groovy WebDriver Sampler编写以下代码和变量.它不起作用,并返回响应代码500"ElementNotInteractableException:元素不可交互".但是我对变量名进行了硬编码并找到了工作. XML变量的问题是动态的,并且每次从Chrome浏览器加载时,数字都会更改.你能请教吗?
变量不起作用: WDS.browser.findElement(org.openqa.selenium.By.xpath("//ul [包含(@ id,'dropdown-menu-')]/li")).click();
可变工作正常: WDS.browser.findElement(org.openqa.selenium.By.xpath("//ul [@ id ='dropdown-menu-2724']/li")).click();
我也尝试了以下代码,但是没有用.
WDS.browser.findElement(org.openqa.selenium.By.xpath("//ul [contains(@ id,'dropdown-menu-')]/li")))sendKeys("dropdown-菜单-"); WDS.browser.findElement(org.openqa.selenium.By.xpath("//ul [starts-with(@ id,'dropdown-menu-')]/li"))).sendKeys("dropdown-menu -");
以下代码也不起作用:
WDS.browser.findElement(org.openqa.selenium.By.id("dropdown-menu-").sendKeys("dropdown-menu-"))); WDS.browser.findElement(org.openqa.selenium.By.id("dropdown-menu-").sendKeys(Keys.ENTER));您还可以看到将硒混合到您的负载方案中文章
I have tired to below code and variable with JMeter Groovy WebDriver Sampler. It's not working and return the Response Code 500 "ElementNotInteractableException: element not interactable". But I hard code the variable name and working find. The problem of XML variable is Dynamic and the numbers will be changed for every time loading from the Chrome. Can you please advise?
Variable not working: WDS.browser.findElement(org.openqa.selenium.By.xpath("//ul[contains(@id,'dropdown-menu-')]/li")).click();
Variable working fine: WDS.browser.findElement(org.openqa.selenium.By.xpath("//ul[@id='dropdown-menu-2724']/li")).click();
I also tried with below codes but didn't work.
WDS.browser.findElement(org.openqa.selenium.By.xpath("//ul[contains(@id,'dropdown-menu-')]/li")).sendKeys("dropdown-menu-"); WDS.browser.findElement(org.openqa.selenium.By.xpath("//ul[starts-with(@id,'dropdown-menu-')]/li")).sendKeys("dropdown-menu-");
below codes also don't work:
WDS.browser.findElement(org.openqa.selenium.By.id("dropdown-menu-").sendKeys("dropdown-menu-")); WDS.browser.findElement(org.openqa.selenium.By.id("dropdown-menu-").sendKeys(Keys.ENTER));
My expectation is that when you use contains() function it tries to click the first element which is found and most probably the one you're trying to click is not the first one matching your XPath query.
We cannot suggest a better way of finding the element without seeing full response, however I would suggest sticking to this Confirm
text and then calculating the preceding-sibling, see XPath Axes article.
Your selector must be:
- Unique
- Matching exactly the element you want to interact with
- The element needs to be visible
- The element needs to be clickable
Selectors can be tested using i.e. browser developer tools
You can also see Mixing Selenium Into Your Load Scenario article
这篇关于JMeter Groovy-具有响应代码500的WebDriver采样器动态名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!