0

In our app that we are using, there are widgets on the page, lots and lots of widgets. There is a HTML tag called widgetkey in it, with an 'id' value associated with it.

Here is the exact HTML:

<div class="widget-wrapper form-group " widgetkey="xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx">

I am hoping that I don't have to get all the elements by that tag name, and then loop through each widget element. The key value is the only thing that makes these widgets unique.

Also steering clear of Xpath, because some of these widgets can not be displayed, causing the widget I am looking for to move location and causing the Xpath to break. The only answer I saw used Xpath. I would rather loop in that case.

2 Answers 2

2

Using xPath should not be a problem. If you know widgetkey then you just use //div[@widgetkey='xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx']

So even if your widget is moved your xPath would not be broken.

4
  • ahhh!!!!! Got it. I see that. Now I know how to find lots of things I have written differently before! Wonderful..I used it mostly to get the embedded value, within an embedded row in a table, in a grid, inside a panel, etc etc....this..this is wonderful! Never thought of it like this. I appreciate that education...and a trophy for you for the quick quick response.
    – Greg P
    Commented Jan 28, 2019 at 15:14
  • I am definitely going to mark this as answered, when I get it working. But this is what the html looks like....the widgetkey is the id name...but still not working...here is the exact html. <div class="widget-wrapper form-group " widgetkey="xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx">. would that change the xpath?
    – Greg P
    Commented Jan 28, 2019 at 15:48
  • @GregP see my update
    – Alexey R.
    Commented Jan 28, 2019 at 15:53
  • 1
    Thank you, sorry for not initially putting in the html. I am going ot put it on the initial question so all the information is there.
    – Greg P
    Commented Jan 28, 2019 at 15:59
0

In top software testing companies this is achieved by many ways some of the options are displayed above and we can achieve this by partially searching for the attribute value like as follow //div[contains(@widgetkey,'XXX')]

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.