1

I am coding in java with selenium and i am stuck. I have to find element by ID, the Id of the element is like this "msi_num_create-copy" (the num is changing every time), there is a way to find the element by part of the Id?

1
  • //*[contains(@id, 'your_sub_string')] , You also have the function starts-with, instead of contains Commented Jul 1, 2021 at 11:38

1 Answer 1

2

yes you would need to use either css selector or xpath :

XPATH would be :

//*[contains(@id, '_create-copy') and starts-with(@id, 'msi')]

and use it like this :

WebElement someEle = driver.findElement(By.xpath("//*[contains(@id, '_create-copy') and starts-with(@id, 'msi')]"));
someEle.click(); or someEle.sendKeys("some string");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.