How debug and use grabAttributeFrom in codeceptjs? - node.js

In my case all identifiers in a page is generated dynamically. So I can't use xpath.
I've found method in the documentation: grabAttributeFrom.
How I can see what's inside, when I using cmd in --debug mode?
Can I use grabAttributeFrom for extracting xpath's from a page when I searching inputs?
How I can get access to inputs which have name and they xpath generates dynamically and I can't use xpath's?
I tried this code:
I.fillField(locate('input').inside('.jq-panel-body-default').at(2),'John');
but it doesn't work correct and generate exception:
FAIL Field "{"type":"xpath","output":null,"strict":true,"locator":{"xpath":".//input[ancestor::*[contains(concat(' ', normalize-space(./#class), ' '), ' jq-panel-body-default ')]][position()=2]"},"value":".//input[ancestor::*[contains(concat(' ', normalize-space(./#class), ' '), ' jq-panel-body-default ')]][position()=2]"}" was not found by text|CSS|XPath

How I can see what's inside, when I using cmd in --debug mode?
Inside.. what?
If you want to log value of attribute, grab it and log:
Scenario("test", async (I) => {
...
const attributeValue = await I.grabAttributeFrom(<locator>, <attribute>);
console.log(attributeValue);
...
});
Can I use grabAttributeFrom for extracting xpath's from a page when I searching inputs?
grabAttributeFrom is for grabbing of attributes value, not for xpath finding.
But if you ask, can you use xpath in locator argument, yes you can.
How I can get access to inputs which have name and they xpath generates dynamically and I can't use xpath's?
This is not enough to ask you. Share some DOM part or something to understand.
If you mean name attribute, you can use filtering by name: //input[#name="<your element name>"]

Related

How can I check if there is a specific parameter in a sails.js request?

How can I check whether there is a specific parameter inside req.param() in sails.js?
For example, I want to check whether the parameter X_id exists in req.param(). If the parameter exists, then I want to use it. If it doesn't exist, then I want to use a default value instead. I've tried the following code:
X_owner: req.param('X_id') || -1,
But I receive an error when I run this code with out X_id parameter. How can I fix the code?
If you're aiming to use default values for your parameters, I'd suggest using actions2 if you haven't tried. It lets you define parameters (using the inputs' object) and use defaultsTo on inputs you want to have default values for, just like in your models attribute definitions. Using these should help resolve the issue.
As for how to check whether there is a specific parameter inside req.param(), you can use req.allParams() to reveal all current parameters from all sources. These include parameters parsed from the url path, the request body, and the query string in that order.

How do you iterate within an Azure Logic App Response component

I have an Azure MS SQL Server component that is returning multiple rows and feeding into a Response component.
The Body of the Response component looks like this:
{
"MyID":"#{body('Get_rows')['value'][1]['Id']}"
}
I can make the number in the bracket 0 and get the first result. I can make it 1 and get the second result. But what I am trying to find is the syntax to loop through all the results that are passed so that it would effectively provide the following (assuming there were 2 results total:
{
"MyID":"#{body('Get_rows')['value'][0]['Id']}"
}
{
"MyID":"#{body('Get_rows')['value'][1]['Id']}"
}
Thanks in advance for advice on where to find the correct syntax or for examples of correct syntax.
It took me a while but figured out that I needed to do two things:
I had to run a for each after the Get Rows and within that I created a Data Operations - Compose component. Within that I was able to create a single JSON object with all the parameters.
From there I used #outputs command as shown below in the Body of the Response and it inserted the array brackets and the commas to delimit the Compose entries automagically.
Here is what the code in the Body of the Response looks like:
#outputs('Compose')
Note that 'Compose' is the default name given to the first Compose component you place in the application.

How to use MarkLogic search options by name

I'm using the ML9 Java API to upload a search options file to the DB with a name that I can use later in my search call. I would now like to write an xquery transform to highlight the query-matches in a set of elements in the response. Standard snippets won't work for me since they only bring back the fields in which there are matches and because they may not bring back the complete field value, but only the immediate context of the match.
So I want to use the cts:highlight function in a custom transform and want to pass to it the name of the options that I have uploaded into the DB. My question is how I can best get the options element from the DB using the name passed in to the transform method. I want to use this to construct the cts:query that I can pass in to the cts:highlight call as in:
let $query := cts:query(search:parse($query-string, $options))
let $result := cts:highlight($doc, $query, <markup>{$cts:text}
</markup>)
I was thinking I could pass in the query-string and the name of the pre-loaded options and use these to construct the cts:query, but don't know how to get the options from the name.
I found a way to avoid having to read the options. Setting the option 'return-query' to true adds a search:query node to the search:response which is passed to the transform method as the document-node. I'm then able to get this directly in the transform method to use in cts:highlight as:
let $query := cts:query($response/search:response/search:query/*[1])
The options are stored in the modules database associated with your REST instance. You could theoretically dig them out, though that would be relying on an implementation detail (the URI).
You might look into a combination of extract-document-data, as Sam mentioned, plus a search result transform, rather than the heavier approach of doing your own search through what I'd guess is a read transform.
Another alternative might be a custom snippeter that you pull into your options via transform-results. See http://docs.marklogic.com/guide/search-dev/query-options#id_58295.

Access document when I have the UID

I have a combobox on my form that loads client names from a view using the format "name | UID" - this displays the client name on the form but saves the UID in the field.
I now want to use the UID to lookup the name for the client and save it in a field on the XPage that is not visible using the following code:
// ignore when UID is null
if (getComponent("parentUID").getValue() == null)
return false;
var UID:string = getComponent("parentUID").getValue();
var doc:NotesDocument = database.getDocumentByUNID(UID);
// now set your fields
document1.setValue("nachname", doc.getItemValueString ("nachname"));
document1.setValue("vorname", doc.getItemValueString ("vorname"));
I do this in a simple action attached to a button. The next simple action is a Save.
The code crashes with the following error:
Error while executing JavaScript action expression
Script interpreter error, line=8, col=42: [TypeError] Exception occurred calling method NotesDatabase.getDocumentByUNID(java.lang.String) null
I have copied the parentUID to a field on the document and I am getting the correct UID and the document exists in the database?
Any ideas?
PS: I am adding this to an existing application and the current document is not a response document - cannot change that unfortunately :o(
OK, I have found my problem - XPages returned the UID but it included a leading space. When I concatenated the values I did the following: "name | UID" i.e. I added a leading and trailing space to the pipe symbol to make the code legible - this was causing the problems.
It looks like you are missing the get.Value() in your getComponent line
Try getComponent("parentUID").getValue() == null
My guess is that this is causing the code to run when the UID is null. This means that the code is running when it really is null, and your effort to check for that isn't working.
Thanks for checking that.
Can you put in a print() statement and ensure that you have a value in the var UID.
Another thing, please capitalize the word "String" since java classes are capitalized.

Excel VBA copy the value of a label from Internet Explorer

I'm trying to retrieve the value "CONGE STATUTAIRE" from the following html code
<span class="DescriptionLabel" id="lblProjectDescription">CONGE STATUTAIRE</span>
I've tried this
nom_proj = IE.Document.getElementsByClassName("DescriptionLabel")(0).innerText
The code pass this line without problem but the the value of nom_proj is " ", and I would have hope to get "CONGE STATUTAIRE" for result.
Could anyone tells me what's wrong with it? The rest of my code is working i.e. I can retrieve value by using the getelementbyID method.
Any help will be welcomed.
I would use the getElementById() method, to make sure it can return only one HTML element and not a collection of objects:
nom_proj = IE.Document.getElementById("lblProjectDescription").innerText
However, the reason why you get "" is most probably that the collection returned by getElementsByClassName() has more than one element (often, when retrieving object by class names).
Which means: in the Document of your browser there will be most probably more elements that are styled with the CSS class DescriptionLabel; for example, something like this:
<div name="emptyRow" class = "DescriptionLabel"></div>
You can test if there are more than one element by:
1) either, adding a watcher to IE.Document.getElementsByClassName("DescriptionLabel");
2) or, printing all the elements inside, I bet my hat you'll find inside more than one:
For Each obj In IE.Document.getElementsByClassName("DescriptionLabel")
Debug.Print obj.InnerText
Next obj
GENERAL SUGGESTION: if an HTML object has an id, use the getElementByID; that method returns a single object, not a collection, so even if you would be sure that the collection will contain a unique element, it would anyway be less clean and efficient in terms of coding.

Resources