storeText ( locator, variableName )
${variableName}
If variableName contains value as 'Displaying 1 to 30 of 145300'.
I need to parse this string and store a value 145300 in another variable.
How is it possible ?
Command: storeEval
Target : '${variableName}'.split(' ').last()
Value : result
Related
${my-string} "FĂȘte : Anniversaire
Emplacement : Paris
Date : 08/12/2021
Prix : texte"
I need to extract the date from this text but i can't end up with a solution using robot framework , i tried :
${REGULAR EXPRESSION} \d{2}\/\d{2}\/\d{4}
Get Regexp Matches ${my-string} ${REGULAR EXPRESSION}
But it gave me null as a result , any solution for that please ?
I think because in Python/Robot Framework the backslash is treated as am escape character, you need an additional backslash on each occassion you use it in your reg ex
e.g. \\d{2}\\/\\d{2}\\/\\d{4}
So something like this should work:
*** Settings ***
Library String
*** Test Cases ***
Check Date Regex
${date} Set Variable FĂȘte : Anniversaire Emplacement : Paris Date : 08/12/2021 Prix : texte
${regex} Set Variable \\d{2}\\/\\d{2}\\/\\d{4}
${matches} Get Regexp Matches ${date} ${regex}
${match} Set Variable ${NONE}
IF ${matches}
${match} Set Variable ${matches}[0]
END
log to console ${match}
With output:
08/12/2021
I have a query with xpath. The values in the xpath is filled dynamically.
Query:
SELECT app_prof.pk_szid, app_prof.xmldata
FROM tblappprofile AS app_prof
WHERE 'Self' =
CAST((xpath('/ApplicationProfile/ComponentIDs/ComponentID[#Family="Core"]/text()', xmldata))[1] AS TEXT)
For preparedStatement:
SELECT app_prof.pk_szid, app_prof.xmldata
FROM tblappprofile AS app_prof
WHERE ? =
CAST((xpath('/ApplicationProfile/ComponentIDs/ComponentID[#Family= ? ]/text()', xmldata))[1] AS TEXT)
When I use,
preparedStatement.setString(1, "Self");
preparedStatement.setString(2, "Core");
results in org.postgresql.util.PSQLException: The column index is out of range: 2, number of columns: 1
The 'Self' is filled correctly. ? in attribute is not recognized. How to use PreparedStatement for attributes in Xpath?
Question marks inside string literals are not considered as parameter placeholders.
You need to pass the whole XPath expression as a parameter:
WHERE ? = CAST((xpath(?, xmldata))[1] AS TEXT)
another option is to dynamically create a string using the format() function:
where ? = CAST((xpath(format('/ApplicationProfile/ComponentIDs/ComponentID[#Family="%s"]/text()',?), xmldata))[1]
That way you can pass the value for #Familiy as a parameter and still keep the XPath inside the SQL if you want.
I created two string variables (tot and tot_value) and assigned a value (tot = MyVal) for testing. Then I created an Execute SQL Task which takes (tot) as parameter and the value returned is saved in tot_value.
In the General Tab, i set:
ResultSet to Single row. SQL Source Type to Direct input Query is listed below.
In Parameter Mapping I selected my tot variable with Input DirectionSQL_VARCHAR Data Type 1 as Parameter Name (Since i am using ODBC)Size set to default -1.
In Result SetResult Name to 1Variable Name to tot_value.
If in the query I hard code 'MyVal' i get the correct result, however when I use ? to use my variable as a parameter, I always get a 0 returned.
Note that my tot variable is set to MyVal
Any clue of what I might be missing? Thanks in advance
select TOP 1 CAST('' + ISNULL((SELECT distinct type_of_transfer_code
FROM SYSTEM.history_program_transfer
WHERE type_of_transfer_value = ?),'') AS VARCHAR(100)) as type_of_transfer_code
FROM SYSTEM.table_facility_defaults
I am trying to read a table having five rows and columns. I have used sql.eachRow function to read eachRow and assign the value to a String. I am getting an error "Groovy:[Static type checking] - No such property: MachineName for class: java.lang.Object"
My code:
sql.eachRow('select * from [MACHINES] WHERE UpdateTime > :lastTimeRead, [lastTimeRead: Long.parseLong(lastTimeRead)])
{ row ->
def read = row.MachineName
}
but MachineName is my column name. How can i overcome this error.
Using dynamic Properties with static type checking is not possible*.
However, eachRow will pass a GroovyResultSet as first parameter to the Closure. This means that row has the type GroovyResultSet and so you can access the value using getAt
row.getAt('MachineName')
should work. In groovy you can also use the []-operator:
row['MachineName']
which is equivalent to the first solution.
*) without a type checking extension.
If you Know the Column name you can just use the Below.
"$row.MachineName"
But if you don't Know column name or having some issue, still it can be accessed using an array of Select.
sql.eachRow('select * from [MACHINES] WHERE UpdateTime > :lastTimeRead, [lastTimeRead: Long.parseLong(lastTimeRead)])
{ row->
log.info "First value = ${row[0]}, next value = ${row[1]}"
}
I have a xpath= //*[#id='00QE000000gQ9fv_ACTION_COLUMN']/a[2]/span
in this xpath 00QE000000gQ9fv is dynamic and _ACTION_COLUMN remains same.
I stored 00QE000000gQ9fv in a String variable as recordId i.e
String recordId = 00QE000000gQ9fv
Now i want a xpath which contains recordId variable.
your xpath will be - //*[contains(#id,'_ACTION_COLUMN')]/a[2]/span
Make sure _ACTION_COLUMN is unique or is the first element in your html so that u grab hold of the right element.
Edit 1 according to your comment.
Try this: //*[contains(#id,'"+recordId +"')]/a[2]/span
or
//*[#id='"+ recordId +"_ACTION_COLUMN']/a[2]/span