I am attempting to use a variable inside of a has-text locator to click the selected Country from a dropdown webpage button element.
My code is:
const dropdown = page.locator(".ta-results");
let country = "India";
console.log(country);
await dropdown.waitFor();
await page.locator(".ta-results:has-text('${country}')").click();
The dropdown is a country selector that autofills based on what you type, so typing "ind" pulls up Indonesia, India, etc. and I am trying to get it to click on "India". By using ".ta-results:has-text('India')").click(); it works fine.
For the course I'm taking the 2nd option works just fine but I would like to find out how to get it to accept a variable for future use.
Based on this previous question it should work. Here is the failure:
=========================== logs ===========================
waiting for locator('.ta-results:has-text(\'${country}\')')
============================================================
92 | console.log(country);
93 | await dropdown.waitFor();
> 94 | await page.locator(".ta-results:has-text('${country}')").click();
| ^
95 | await page.pause();
96 | });
97 |
Note that in the question you linked, they were using template literals, a string surrounded by backticks (`) which in JavaScript allows interpolation, or inserting things like variables or other expressions, unlike some other languages where double quotes allows this. So you just need to switch the quote type on your string like so:
`.ta-results:has-text('${country}')`
You could also use one of the filter option approaches provided by Playwright:
Using the hasText option specific to the locator method:
await page.locator(".ta-results”, { hasText: country }).click();
Using the hasText option within the filter method:
await page.locator(".ta-results”).filter({ hasText: country }).click();
Related
I've searched for a while trying to find a way in Postman to extract a HTML description list value from the response body where the description list contains multiple values.
Example of response body:
<dl>
<dd>Fruit</dd>
<dt>Apple</dt>
<dd>Vegetable</dd>
<dt>Carrot</dt>
</dl>
How do I just get just the Vegetable value? I've tried using the following
const $ = cheerio.load(pm.response.text())
console.log('Vegetable', $('dt').text())
This then returns both values
"Vegetable" "AppleCarrot"
The Fruit & Vegetable values will change once the request is rerun, this means I'm unable to go just based off their names.
I'm probably over thinking this, thanks in advance.
EricG posted the following above.
JQuery allows you to filter based off order using the following:
const $ = cheerio.load(pm.response.text())
console.log('Vegetable', $('dt').first().text())
Alternatively to the above if you need to go further down the list you can use:
const $ = cheerio.load(pm.response.text())
console.log('Vegetable', $('dt').eq(0).text())
Changing the value in .eq(#) starting from 0 will then following the items down the list.
I im newbie in splunk.
I have this json:
"request": {
"headers": [
{
"name": "x-real-ip",
"value": "10.31.68.186"
},
{
"name": "x-forwarded-for",
"value": "10.31.68.186"
},
{
"name": "x-nginx-proxy",
"value": "true"
}
I need to pick a value when the property name has "x-real-ip" value.
There are a couple ways to do this - here's the one I use most often (presuming you also want the value along side the name):
index=ndx sourcetype=srctp request.headers{}.name="x-real-ip"
| eval combined=mvzip(request.headers{}.name,request.headers{}.value,"|")
| mvexpand combined
| search combined="x-real-ip*"
This skips all events that don't have "x-real-ip" somewhere in the request.headers{}.name multivalue field
Next, it combines the two multivalue fields (name & value) into a single mv field, separated by the | character
Then expand the resultset so you're looking at one line at a time
Finally, you look for only results that have the value "x-real-ip" in them
If you'd like to then extract the value from the combined field, add the following line:
| rex field-combined "\|(?<x_real_ip>.+)"
And, of course, you can do whatever other SPL operations on your data you wish
I tried #Warren's answer but I got the following error:
Error in 'eval' command: The expression is malformed. Expected ).
You need to add a rename because the {} charcters in mvzip causes problems.
This is the query that works:
index=ndx sourcetype=srctp request.headers{}.name="x-real-ip"
| rename request.headers{}.name AS headerName, request.headers{}.value AS headerValue
| eval reviewers=mvzip(headerName,headerValue ,"|")|
| mvexpand combined
| search combined="x-real-ip*"
your search
| rex max_match=0 "name\":\s\"(?<fieldname>[^\"]+)"
| rex max_match=0 "value\":\s\"(?<fieldvalue>[^\"]+)"
| eval tmp=mvzip(fieldname,fieldvalue,"=")
| rename tmp as _raw
| kv
| fields - _* field*
When you ask a question, please present the correct information.
You've run out of logs in the process.
I am new at programming altogether and need your help in finding a way out to the below query:
I need to find all the fields on a 'abc_contact' page with same field type (single line of text and multiple lines of text) and then perform some logical operation. How can I get all the fields of same type through JavaScript?
As #Guido points out in his comment, you can access an attribute's type using:
Xrm.Page.getAttribute(arg).getAttributeType()
You can get all of the attributes from the entity attribute collection, loop through them and get their types:
Xrm.Page.data.entity.attributes.forEach(function (attribute, index) {
var attributeType = attribute.getAttributeType();
// Perform logic based on attribute type
});
Attributes collection reference: https://msdn.microsoft.com/en-us/library/gg334720.aspx#BKMK_entityattributes
Type TYP = (entityObj.Attributes["columnName"]).GetType();
string TypeVal = TYP.FullName.ToString();
New to DynamoDB and need to do the above query, but not sure how. Here is what I'm trying currently, and I'm getting the error below.
Btw, I am using this javascript library w/ DynamoDB: https://github.com/awslabs/dynamodb-document-js-sdk
var ids = ['12313','12312313','12312313'];
var params = {
TableName: 'apps',
IndexName: 'state-app_id-index',
KeyConditions: [
DynamoDB.Condition("state", "EQ", "active"),
DynamoDB.Condition("id", "IN", ids)
]
};
DynamoDB.query(params, function(error, response) {});
The error I am getting is as follows:
ValidationException: One or more parameter values were invalid: ComparisonOperator IN is not valid for L AttributeValue type
KeyConditions does not support the IN operator. The documentation for KeyCondition says what operators it does support:
For KeyConditions, only the following comparison operators are
supported:
EQ | LE | LT | GE | GT | BEGINS_WITH | BETWEEN
The EQ operator only works for a single value as well:
EQ : Equal.
AttributeValueList can contain only one AttributeValue of type String, Number, or Binary (not a set type). If an item contains an AttributeValue element of a different type than the one specified in the request, the value does not match. For example, {"S":"6"} does not equal {"N":"6"}. Also, {"N":"6"} does not equal {"NS":["6", "2", "1"]}.
The restrictions are basically the same for KeyConditionExpression, which is the newer, recommended way for filtering on keys. Here is a snippet from the documentation (emphasis mine):
The condition must perform an equality test on a single hash key
value. The condition can also perform one of several comparison tests
on a single range key value. Query can use KeyConditionExpression to
retrieve one item with a given hash and range key value, or several
items that have the same hash key value but different range key values
In your case, you could build out the FilterExpression in a similar way as described in this answer.
The only way to use the IN statement is by using a filter Condition.
However Filter expression can only contain non-primary key attributes.
Thus the query you want to achieve is NOT possible with primary keys.
Something like this
var params = {
TableName: 'apps',
...
FilterExpression: "#id IN (:one,:two)",:
...
Is only possible with non-primary key attributes
The workaround you can apply is using the batch get item
Therefore instead of issuing one query issue multiples in one call and each condition shall contain a value from your ids array.
When it comes to batch get items be aware of the read capacity units (batch get item in node.js).
I am building a system where users associate tags with posts, not unlike SO. I am having a spot of bother implementing tag synonyms.
Here I have a table called Tags:
| TagName |
|------------|
| Python |
| JavaScript |
| Node |
And I have another called TagSynonyms:
| SynonymId | SourceTagName | TargetTagName |
|-----------|---------------|---------------|
| 1 | Py | Python |
| 2 | Python2 | Python |
The server is implemented using Node and the user enters some tags as a comma-delimited string:
var input = 'Py,Flask'
var tags = request.tags.split(',');
In this case, the user has entered the tag Py which, according to the TagSynonyms table, should be mapped to the tag Python. The second tag, Flask has no synonym and should remain the same.
I managed to implement this functionality using imperative code:
tags.forEach(function (tag) {
connection.query('SELECT TargetTagName FROM TagSynonyms WHERE SourceTagName = ?', tag, function(err, rows) {
if (rows.length !== 0) {
console.log(rows[0].TargetTagName);
} else {
console.log(tag);
}
});
});
Here, the user input
['Py','Flask']
results in the following output
Python
Flask
What I want to do is, defer this logic to the database engine, as I think using a loop is a code smell. I also think the database engine will be more performant. What is an appropriate query to do this?
You need a UNION and a join:
select TagName
from Tags
where TagName in (?,?,?,...)
union
select TagName
from Tags
join TagSynonyms
on Tags.TagName = TagSynonyms.TargetTagName
where TagSynonyms.SourceTagName in (?,?,?,...)
Note that union can be slow since it will try to remove duplicates. If that's the case for you, use union all and remove duplicates in the application code.
(?,?,?,...) stands for a list of input values; check your DB driver documentation for the exact syntax that you need to use to avoid SQL injection.
Update: Here is what the implementation will look like in Node:
var query =
'SELECT TagName \
FROM Tags \
WHERE TagName IN (?) \
UNION \
SELECT TagName \
FROM Tags \
JOIN TagSynonyms \
ON Tags.TagName = TagSynonyms.TargetTagName \
WHERE TagSynonyms.SourceTagName IN (?)'
connection.query(query, [tags, tags], function(err, rows) {
tags = rows.map(function(row) {
return row.TagName
});
});