XPath for accessing an element thru CSS style

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
aterrong
Posts: 6
Joined: Thu May 26, 2016 11:43 am

XPath for accessing an element thru CSS style

Post by aterrong » Thu May 26, 2016 1:15 pm

Hi,
I'm trying to access the following element thru style tag:

<div tabindex="-1" class="ui-dialog ui-widget ui-widget-content ui-corner-all ui-resizable" role="dialog" aria-labelledby="ui-id-14" style="outline: 0px; left: 806.5px; top: 264.5px; width: 300px; height: auto; display: block; position: absolute; z-index: 1027;">

but if I try with a Xpath like:

/dom[@domain...]//div[@style~'display: block']

to just select the visible element of many similar ones Ranorex Spy can't identify it.

How should I be writing the Xpath to identify such element?

TIA

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: XPath for accessing an element thru CSS style

Post by krstcs » Fri May 27, 2016 2:32 pm

You are going to have to make your path more specific until it captures ONLY the element you want.

You either need to add more attributes or add more parent elements (or both) in order to ensure that Ranorex ONLY finds the specific element you want.

Using CSS style is usually not a good way to do anything with RanoreXPath because the CSS can change and many elements can have the same style.

Please post a Ranorex SNAPSHOT (NOT a screenshot!) of the element and someone here might be able to help you with it more.
Shortcuts usually aren't...

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

Re: XPath for accessing an element thru CSS style

Post by odklizec » Fri May 27, 2016 2:37 pm

Hi,

The xpath looks OK to me? And Ranorex 6.0 found the div without a problem (I've tried the HTML code in FF at http://www.w3schools.com). But I agree with Kelly, that you should use a bit more detailed xpath to avoid problems with multiple elements. BTW, what version of Ranorex do you use?
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