Robotframework [Return] - return

Check AppData Count
${count}= Get Text css:mycssLocator
Log ${count}
[Return] ${count}
I am trying to get a count from a css locator and then return the text for use in other keywords, however I'm not sure that my syntax is working correctly.
When I try and use ${count} in a subsequent keyword, it isn't found - I understood [Return] as making the return available outside the keyword scope?

You must save the value returned by a keyword if you want to use it later.
For example:
${count}= check appdata count
log count: ${count}

Related

=importxml, Website to Google Sheets - getting #N/A every time

Website Link
https://redacted
xml options I have tried so far
<span aria-labelledby="amount">722</span>
//*[#id="amount"]/h3/span[2]
/html/body/div[3]/main/div/span/div/div/div[2]/div/div/div[2]/div/div[2]/div[3]/div/div/div/div[2]/div[1]/h3/span[2]
None working
Trying to =importxml from here # a value of "722" this is value on 5/5/22 anyway.
Unfortunately, it seems that your expected value cannot be directly retrieved using the XPath. Because the value is put to the HTML using Javascript and IMPORTXML cannot analyze the result of Javascript. But, fortunately, it seems that your expected value is included in the HTML as the JSON data. So, in this answer, I would like to retrieve the value from the JSON data.
Pattern 1:
In this pattern, IMPORTXML and REGEXEXTRACT are used.
=ARRAYFORMULA(REGEXEXTRACT(IMPORTXML(A1,"//script[#data-component-name='GetOfferWrapper']"),"defaultEstimatedValue"":(.+?)}"))
The URL https://www.gazelle.com/iphone/iphone-13-pro-max/other/iphone-13-pro-max-1tb-other/498082-gpid is put in the cell "A1".
When this formula is used, the following result is obtained.
Pattern 2:
In this pattern, a custom function created by Google Apps Script is used. When the value is retrieved from JSON data, Google Apps Script is useful. When you use this script, please copy and paste the following script to the script editor of Spreadsheet and save the script. And, please put a custom function of =SAMPLE("https://www.gazelle.com/iphone/iphone-13-pro-max/other/iphone-13-pro-max-1tb-other/498082-gpid") to a cell.
function SAMPLE(url) {
const res = UrlFetchApp.fetch(url).getContentText();
const data = res.match(/<script.+data-component-name="GetOfferWrapper".+?>([\w\s\S]+?)<\/script>/);
if (!data || data.length == 0) return "No data";
const obj = JSON.parse(data[1]);
return obj.initState.defaultEstimatedValue;
}
The URL https://www.gazelle.com/iphone/iphone-13-pro-max/other/iphone-13-pro-max-1tb-other/498082-gpid is put in the cell "A1".
When this formula is used, the value of 722 is retrieved.
Note:
The formula and custom function can be used for the current HTML. So, when the specification of HTML is changed, those might not be able to be used. Please be careful about this.
References:
IMPORTXML
REGEXEXTRACT
Custom Functions in Google Sheets
fetch(url)
JSON.parse()
you will need to find another site with intel you attempting to scrape. the #N/A error is the result of google sheets not supporting the import of JavaScript elements. you can always check for compatibility by disabling JS in site settings and only what's left can be usually scrapped. in this case its nothing:

How to detect if a field contains a character in Lua

I'm trying to modify an existing lua script that cleans up subtitle data in Aegisub.
I want to add the ability to delete lines that contain the symbol "♪"
Here is the code I want to modify:
-- delete commented or empty lines
function noemptycom(subs,sel)
progress("Deleting commented/empty lines")
noecom_sel={}
for s=#sel,1,-1 do
line=subs[sel[s]]
if line.comment or line.text=="" then
for z,i in ipairs(noecom_sel) do noecom_sel[z]=i-1 end
subs.delete(sel[s])
else
table.insert(noecom_sel,sel[s])
end
end
return noecom_sel
end
I really have no idea what I'm doing here, but I know a little SQL and LUA apparently uses the IN keyword as well, so I tried modifying the IF line to this
if line.text in (♪) then
Needless to say, it didn't work. Is there a simple way to do this in LUA? I've seen some threads about the string.match() & string.find() functions, but I wouldn't know where to start trying to put that code together. What's the easiest way for someone with zero knowledge of Lua?
in is only used in the generic for loop. Your if line.text in (♪) then is no valid Lua syntax.
Something like
if line.comment or line.text == "" or line.text:find("\u{266A}") then
Should work.
In Lua every string have the string functions as methods attached.
So use gsub() on your string variable in loop like...
('Text with ♪ sign in text'):gsub('(♪)','note')
...thats replace the sign and output is...
Text with note sign in text
...instead of replacing it with 'note' an empty '' deletes it.
gsub() is returning 2 values.
First: The string with or without changes
Second: A number that tells how often the pattern matches
So second return value can be used for conditions or success.
( 0 stands for "pattern not found" )
So lets check above with...
local str,rc=('Text with strange ♪ sign in text'):gsub('(♪)','notation')
if rc~=0 then
print('Replaced ',rc,'times, changed to: ',str)
end
-- output
-- Replaced 1 times, changed to: Text with strange notation sign in text
And finally only detect, no change made...
local str,rc=('Text with strange ♪ sign in text'):gsub('(♪)','%1')
if rc~=0 then
print('Found ',rc,'times, Text is: ',str)
end
-- output is...
-- Found 1 times, Text is: Text with strange ♪ sign in text
The %1 holds what '(♪)' found.
So ♪ is replaced with ♪.
And only rc is used as a condition for further handling.

LoadRunner web_reg_save_param, ord=all, paramName_count issues

I am using LoadRunner version 12.02 - Build 2739
Looking at an old, yet correct 'guide' shows that I have used the statements correctly (3rd Point, around 1/3rd of the way down the page, inside the code block - the atoi statement).
But I am still unable to convert the _count parameter to an int-Variable.
In the script, before the call is made;
web_reg_save_param(
"ParamName=rotaPeople",
"LB=someText",
"RB=\")",
"Ord=ALL",
LAST);
After the web call the save_param function is placed before, the output log shows;
Notify: Saving Parameter "ParamName=rotaPeople_count = 21".
Inside the script, after the call is made, and the count has been totaled;
lr_output_message("RP_C:%d",lr_eval_string("{rotaPeople_count}"));
lr_output_message("RP_C:%s",lr_eval_string("{rotaPeople_count}"));
peoplesCount = atoi(lr_eval_string("{rotaPeople_count}"));
lr_output_message("PC:%d",peoplesCount);
In the logs after the above executions are made;
Warning: The string 'rotaPeople_count' with parameter delimiters is not a parameter.
RP_C:110826864
Warning: The string 'rotaPeople_count' with parameter delimiters is not a parameter.
RP_C:{rotaPeople_count}
Warning: The string 'rotaPeople_count' with parameter delimiters is not a parameter.
PC:0
Anyone have any ideas?
Note: The Warning messages are expected
Note: Workaround: Used web_reg_save_param_regex() and created a regular expression. Using the returned _count parameter within a for-loop worked. Keeping question open, as the original problem still persists
The problem is that you use a soon to be deprecated API web_reg_save_param which does not support the ParamName syntax. In this API the second parameter is always the parameter name and therefore the correct use would be:
web_reg_save_param(
"rotaPeople",
"LB=someText",
"RB=\")",
"Ord=ALL",
LAST);
The proper API to use is web_reg_save_param_ex which does support the syntax you used so the call should look like:
web_reg_save_param_ex(
"ParamName=rotaPeople",
"LB=someText",
"RB=\")",
"Ord=ALL",
LAST);
Then the rest of your code should work properly.
I am not sure what you are doing but you might want to take a look at the somewhat unknown API lr_paramarr_random which will automatically pull a random value from the parameters array.
This should help you
web_reg_save_param(
"rotaPeople",
"LB=someText",
"RB=\")",
"Ord=ALL",
LAST);
lr_output_message("PC:%d",atoi(lr_eval_string("{rotaPeople_count}")));
You are using ord=all,see the run time data which value you want to capture,If you want to capture the 10th value please use ord=10,automatically this warning will remove from output log.
Example for capturing an array of dynamic values:
Action()
{
int i;
int ncount;
char ParamName[100];
web_set_sockets_option("SSL_VERSION", "TLS");
web_reg_save_param("trackingno","LB=;","RB= (NTN 0430)","search=All","ord=all",LAST);
web_submit_data("barcode.pl",
"Action=http://qtetools.rmtc.fedex.com/barcode/cgi-bin/barcode.pl",
"Method=POST",
"TargetFrame=",
"RecContentType=text/html",
"Referer=http://qtetools.rmtc.fedex.com/barcode/html/barcode.shtml",
"Snapshot=t2.inf",
"Mode=HTML",
ITEMDATA,
"Name=formcode", "Value=0430", ENDITEM,
"Name=count", "Value=10", ENDITEM,
"Name=narrow", "Value=2", ENDITEM,
LAST);
ncount= atoi(lr_eval_string("{trackingno_count}"));
for (i =1;i <= ncount;i++)
{
sprintf(ParamName, "{trackingno_%d}", i);
lr_output_message("Value of %s: %s",ParamName,lr_eval_string(ParamName));
}
return 0;
}

API to modify Firefox downloads list

I am looking to write a small firefox add-on that detects when files that were downloaded are (or have been) deleted locally and removes the corresponding entry in the firefox download list.
Can anybody point me to the relevant api to manipulate the download list? I cannot seem to find it.
The relevant API is PlacesUtils which abstracts the complexity of the Places database.
If your code runs in the context of a chrome window then you get a PlacesUtils glabal variable for free. Otherwise (bootstrapped, Add-on SDK, whatever) you have to import PlacesUtils.jsm.
Cu.import("resource://gre/modules/PlacesUtils.jsm");
As far as Places is concerned, downloaded files are nothing more than a special kind of visited pages, annotated accordingly. It's a matter of just one line of code to get an array of all downloaded files.
var results = PlacesUtils.annotations.getAnnotationsWithName("downloads/destinationFileURI");
Since we asked for the destinationFileURI annotation, each element of the resultarray holds the download location in the annotationValue property as a file: URI spec string.
With that you can check if the file actually exists
function getFileFromURIspec(fileurispec){
// if Services is not available in your context Cu.import("resource://gre/modules/Services.jsm");
var filehandler = Services.io.getProtocolHandler("file").QueryInterface(Ci.nsIFileProtocolHandler);
try{
return filehandler.getFileFromURLSpec(fileurispec);
}
catch(e){
return null;
}
}
getFileFromURIspec will return an instance of nsIFile, or null if the spec is invalid which shouldn't happen in this case but a sanity check never hurts. With that you can call the exists() method and if it returns false then the associated page entry in Places is eligible for removal. We can tell which is that page by its uri, which conveniently is also a property of each element of the results.
PlacesUtils.bhistory.removePage(result.uri);
To sum it up
var results = PlacesUtils.annotations.getAnnotationsWithName("downloads/destinationFileURI");
results.forEach(function(result){
var file = getFileFromURIspec(result.annotationValue);
if(!file){
// I don't know how you should treat this edge case
// ask the user, just log, remove, some combination?
}
else if(!file.exists()){
PlacesUtils.bhistory.removePage(result.uri);
}
});

Issue with using int.parse() in Dart

I'm currently teaching myself the Dart language, and my first app doesn't seem to be working right. Here's the code that's causing trouble:
usrLoc = int.parse(query("#txtLoc").text);
When I try to run the app, it opens fine, but when I click the button that triggers this (and three other similar parses), the debugger stops and tells me "Source not found" for int._native_parse(), int._parse(), and int.parse().
Any help would be greatly appreciated.
The text property for the specified element #txtLoc returns an empty string.
The parse method requires that:
The source must be a non-empty sequence of base- radix digits, optionally prefixed with a minus or plus sign ('-' or '+').
You can specify an onError named argument in your call to parse, which takes a callback that handles the invalid input. E.g., if you want the parse call to return the value 42 for all invalid input, you can do this:
usrLoc = int.parse(query("#txtLoc").text, onError: (val) => 42);
If you really expect the element to have some text, you can store the result of query("#txtLoc").text into a separate variable and verify the value. It would also be interesting to check what the real element type is or which tag is marked with id #txtLoc.
If you want to get the content of an input element, you should use the value property instead of text:
query("#txtLoc").value

Resources