Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
376 views
in Technique[技术] by (71.8m points)

JMeter Groovy - WebDriver Sampler Dynamic Name with Response Code 500

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

enter image description here

enter image description here

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

  1. Unique
  2. Matching exactly the element you want to interact with
  3. The element needs to be visible
  4. 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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...