While reading an online blog i came across the below xpath,
xpath=//body/div[3]/form/fieldset/select[count(*)>1]
and the UI HTML looks like
What will be the xpath output? Is the Author tries to check whether the Select options are more than one ? (boolean answer)
This query will return all <select/> elements with more than one option to choose from. If so, the predicate is true and the <select/> element gets included, otherwise not.
Actually this is not quite correct, as it would fail to recognize <option/>s in <optgroup/>s:
<select>
<optgroup>
<option>foo</option>
<option>bar</option>
<option>batz</option>
</optgroup>
</select>
Which definitely has more than one option, but still only one direct child node. A better solution probably would be to use (I cut off the path in the beginning).
//select[count(.//*)>1]
Related
This question already has an answer here:
Can you use wildcard characters with tags to get all matching tags
(1 answer)
Closed 1 year ago.
We are using tags to be able to group features and senarios. For example, we have something like:
#jira=123
Scenario: test scenario 1
...
#jira=456
Scenario: test scenario 2, known failure
...
Scenario: test scenario 3, new feature
Now, we are hoping to run test that are not tagged with #jira=123 or #jira=456. Because we have many features and scenarios tagged with the #jira=somevalue, it is impractical to add them all. So I am looking for a way to be able to exclude anything tagged with #jira. I tried ~#jira and "~#jira=" but no luck.
Looking at the following junit case:
TagTest.java#testToString()
Which is using "#foo=" as a tag, but was not able to find an example. Is there a way to exclude a group of scenarios tagged by #jira, regardless of the tag value ?
The tag value is the whole string, even if it contains a = and you may assume there is key and a value.
But you could consider to use multiple tags, they are allowed.
So, in your case, I would use something like:
#jira=123
#jira
Scenario: test scenario 1
...
#jira=456
#jira
Scenario: test scenario 2, known failure
And the you can use the ~#jira to exclude all the #jira scenarios.
This will allow you to still reference the single #jira=123 when needed.
Yes, we haven't documented this well but this question here can be a start. Karate actually supports a mini expression language for tags.
Have a look at this test for some options: TagsTest.java
And this should work for your requirement, do confirm in the comments ! Yes just use the string below where you would normally put #jira etc.
!valuesFor('#jira').isPresent
One more important point. When you use the special expression language, any AND or OR complexity has to be managed within the single expression that you pass into the tags option. Only one expression is needed and the use of comma-separated values or multiple values for the tag parameter is not applicable.
For example:
To select scenarios that have values for either the #fail tag or the #bad tag (note the use of the JS || (OR) operator):
valuesFor('#fail').isPresent || valuesFor('#bad').isPresent
And to select any scenario that has values for the #fail tag and where the #smoke tag is present (without values, just the plain tag and no = part):
valuesFor('#fail').isPresent && anyOf('#smoke')
And yes, you can use the "expression language" on the command-line i.e. within the karate.options or as the --tags or -t option to the stand-alone JAR: https://stackoverflow.com/a/72054253/143475
I went through the Merge Tags here and here, but couldn't figure out the syntax that would allow me to show content based on whether the user has certain Tag or not.
Help?
My goal in case it helps:
User subscribes, and is queued for a welcome mail one day later. In meantime that user may get tagged (my way of segmenting them), and so, the next day when that user receives the welcome mail, the content needs to be catered based on the tag that user got.
Got a response from their support saying
merge tags do not work with Tags just yet
here's the whole thing:
While we do have conditional merge tags available, I'm afraid we do
not have any that would work with Tags. To be transparent, Tags were
recently added a few months ago, and there are some features in our
application that has not updated to work with Tags just yet.
Because conditional merge tags do not work with tags yet, the best
option would be to create multiple automations and send them out based
on each tags. If you do it that way, you'll be able to target those in
specific tags with specific content
Dug a little deeper from the first link. There is another link Use Conditional Merge Tag Blocks which contained the below code:
Name
IF-ELSE
Definition
Use ELSE to indicate alternative content to display if the *|MERGE|* tag value is false.
Example
*|IF:MERGE|* content to display *|ELSE:|* alternative content to display *|END:IF|*
Name
ELSEIF
Definition
Use ELSEIF to specify a new *|MERGE|* tag to be matched against if the first *|MERGE|* tag value is false.
Example
*|IF:TRANSACTIONS >= 20|* Enjoy this 40% off coupon! *|COUPON40|*
*|ELSEIF:TRANSACTIONS >= 10|* Enjoy this 20% off coupon! *|COUPON20|*
*|ELSE:|* Enjoy this 10% off coupon! *|COUPON10|* *|END:IF|*
More examples with definitions can be found here.
Hope this is the answer you were after.
I want to use 2 conditions in stencil theme (bigcommerce). How can I do so?
{{#if schema && product.brand.name '!=' ''}}
I have also used
{{#all schema product.brand.name '!=' ''}}
but did not get the desired result.
Also how can we check whether some variable or property is empty or not because following statement did not work for me:
{{#if product.brand.name '==' ''}}
Regards,
You should be able to use the {{#and}} helper to compare exactly two conditions.
{{#and schema product.brand.name}} There's both a schema and brand name! {{/and}}
This will check that both "schema" and "product.brand.name" evaluate to something truthy (meaning they're defined and they're not explicitly False or 0, etc)
Checking if a variable is empty is similarly just an if statement checking for it being defined:
{{#if customer}} There's a customer! {{/if}}
There's lots of good examples of these helpers being used in the Cornerstone repo, it might be helpful to search that repo for a few examples to get a feel for things.
Here's an example of the "and" helper: https://github.com/bigcommerce/cornerstone/blob/3350ea5c2a8cbb53819145bdcdda41dc6fef4f0c/templates/components/products/price-range.html#L1
Hope this helps!
I am trying to locate web elements using the element id. But the id of the same web element changing between
Driver.findElement(By.id("ItemDetailsCompView.**Edit**ViewUIElement_Field_Tab_2_Product_Materials"))
and
Driver.findElement(By.id(ItemDetailsCompView.**Display**ViewUIElement_Field_Tab_2_Product_Materials"))
This results in to an error when I have hard coded for one id and the other id occurs. Is there a way to create a string that searches for Edit / Display words in the id.
I am unable to use Xpath as my webpage is complex and consists of various nested tables.
You could try using a CSS selector (the syntax may be incorrect here, it's not clear what language you are using):
Driver.findElement(By.CssSelector([id*="ViewUIElement_Field_Tab_2_Product_Materials"]))
Even better if you can provide an element tag name on that.
In my website there is a recently uploaded image section.
in this section all recently uploaded images are displayed randomly
using firepath i traced the xpath of that location
//div[#id='udtkbdf50']/a/div[2]/div
so on each time page refresh this #id='udtkbdf50' value changes ,only one thing is common that is the value is always starting with u
so i want to use pattern matching technique [regular expression or Globbing Patterns ]
#id='udtkbdf50' for this value and rest of the path i.e /a/div[2]/div will remain same.
//div[contains(#id,'u')]/a/div[2]/div will work.
UPDATE:
//div[starts-with(#id,'u')]/a/div[2]/div will be more specific.
All d best.