-1

Example A:

I need to make below object as dynamic as possible, in order to have robust/flexibility. this is an upload button, but the value of element tend to change for time being:

xpath="//input[@id='**j_idt162:input**'] , 

so i tried below :

xpath="//input[@id='j_idt[0-9],{1,4}:input']

Example B: i have lists of caseIDs, i only need to get one of it. doesnt matter from the top or down. instead of using static below

xpath = "//a[contains(.,'3131')]")

i tried this

xpath = "//a[contains(.,'^[0-9]{1,5}$')]"), "index:=0" 

none of above is working, Example A, i tried to only give 4 digit number but range is dynamic.

Example B, I'm trying to let it pick up only first one link with with limited to range 5, for instance (12345)'

Thanks in advance for answering

HTML node example

  • 2
    Can you share your HTML – Monika Jul 18 '17 at 16:05
  • Please read [ask], especially the part about [mcve] (MCVE), and [How much research effort is expected?](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users) This will help you debug your own programs and solve problems for yourself. If you do this and are still stuck you can come back and post your MCVE, what you tried, and the execution result including any error messages so we can better help you. Also provide a link to the page and/or the relevant HTML. – JeffC Jul 18 '17 at 18:28
  • Hey @Monika. i can't copy the html and due to the policy. i have a partial non confidential node. but can't paste the screenshot for some reason.so i have add a url in the original post above. – MemphisTony V Montana Jul 24 '17 at 15:02
  • @JeffC: Sure, URL provided. will keep in mind. – MemphisTony V Montana Jul 24 '17 at 15:05
  • You didn't provide the URL, you provided a screenshot of HTML which is [a bad idea](https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors). Paste the code and properly format it instead. In the HTML you provided, there is no element with an ID so now I'm really confused as so what you are trying to do. You need to reread your question and make sure that you've provided everything we need to help solve this issue. It should contain a clear statement of the problem, a link to the site or relevant HTML, your code attempts, and the full error messages. – JeffC Jul 24 '17 at 18:54

1 Answers1

0

It's not possible to use Regex in XPath 1.0, and most browsers support XPath 1.0 only.
You'd better use prefix and suffix in class or id. Then use start-with() and end-with() or contains() to find the element. For example,

//*[starts-with(@id, 'sometext') and ends-with(@id, '_text')]

Check this answer.

Buaban
  • 5,029
  • 1
  • 17
  • 33
  • Hey, Buaban. thanks for the clerification. at least i understood that you can't use with that extent yet. However because i can't predict it will start or end with certain number, or contain. i can't use this as final solution. – MemphisTony V Montana Jul 24 '17 at 14:53
  • @MemphisTonyVMontana I know. I use to be in this situation. I gave up the regex searching because I can't wait for xpath 2.0. You may filter the elements with some certain attribute and then iterate all the results and use Regex in Java to find that particular element. – Buaban Jul 25 '17 at 01:11