Using regexp for FindElement
Hello,
I read several other forum post similar to my issue and seems like regexp and FindElement may not work.
I got the following dynamic xpath: FindElement("//div[@id='__49_0']//input") Unfortunately, this is the only selector detected by TestComplete to identify the textbox. The dynamic part of the selector are the numbers.
I was thinking of using a regex and came up with the expression: Page.FindElement("regexp:\/\/div\[\@id='__\d+_\d+']\/\/input')") I am using JavaScript so I may be missing some backslashes to escape characters, not sure.
I am using TestComplete 15, and seems like when using the Find methods, only xpath 1.0 is supported so the xpath functions to recognize a strings is limited.
By the way, when the FindElement method is successful, does it automatically click on the object?
Any suggestions?
Regards.
I am using TestComplete 15 and seems like only xpath 1.0 is supported when used with the Find methods. Am I right on that?
Hi enriquebravo,
I am not a xpath expert...if the id number is dynamic, and id isn't unique to that div element, then you shouldn't have to look for the id attribute in your expression. Something like this might work: FindElement("//div//input")
if the id is unique to that div element then you can simply verify that it exists, something like this might work: FindElement("//div[@id]//input")
if part of the attribute is unique, like the underscores, then you might be able to use the contains method, like this: FindElement("//div[contains(@id, '__')]//input")
Not sure if any of this works or helps, but I thought I'd share.