Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...