Identifying Xpath via UserCode

Class library usage, coding and language questions.
Rich63
Posts: 1
Joined: Wed Jul 10, 2019 10:27 am

Identifying Xpath via UserCode

Post by Rich63 » Wed Jul 10, 2019 10:35 am

I'm currently running automative tests against a web application. However, I'm struggling at selecting dynamic dates set via usercode. Below is a modifed snippet of my workings:

String searchDate = DateTime.now.AddDays(1).ToString();

//..
formating searchDate correctly
...//

string selector = "/dom[@caption~'^site title']//div[#'paginator']/ul/li/a[@innerText~'^searchDate']";
Element elementX = Ranorex.Core.Element.FromPath(selector);

When inspecting elementX its Null. The selector above being used is from Ranorex Spy also.

Any help is appreciated

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 5280
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Identifying Xpath via UserCode

Post by odklizec » Fri Jul 12, 2019 8:21 am

Hi,

To apply variable in code, you must use it like this:

Code: Select all

string selector = "/dom[@caption~'^site title']//div[#'paginator']/ul/li/a[@innerText~'^"+ searchDate+"']";
BTW, please post a Ranorex snapshot (NOT screenshot) of UI you are trying to automate. This would help us to understand your UI and eventually suggest best approach.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration