How to store the content/value of xpath? - xpath

Assume xpath as below:
xpath : //div[#id='cslGridViewPanelControl']/div/div[2]/div/table/tbody/tr/td[2]/table/tbody/tr/td/table/tbody/tr/td/div
Last div element contains 'Displaying 1 to 30 of 145300'.
I need to store 'Displaying 1 to 30 of 145300' in some variable by using selenium tool.
I tried
command target value
store xpath variable1
echo ${variable1}
It displays as variable1: xpath. But i need variable1: 'Displaying 1 to 30 of 145300'.
Can anyone help me please ?

Try storeText ( locator, variableName )
Then use it ${variableName}
Refer Selenium documentation for storeText

saga told you how to store that string, as you need to store only 145300, below code will help you
store | Displaying 1 to 30 of 145300 | string
store | 1 | delimiter
store | javascript{storedVars['string'].split('of')[storedVars['delimiter']]} | result
echo | ${result}

Related

PowerAutomate - replace nth occurrence of character

I'm attempting to parse email body to excel file.
After some manipulations, my current output is an array, where each line is data related to a product.
[  
"Periods: 01.01.2023 - 01.02.2023 | Code: 111 | Code2: 1111 | product-name",  
"Periods: 01.01.2023 - 01.02.2023 | Code: 222 | Code2: 2222 | product-name2"
]
I need to replace the 3rd occurrence of " | " with " | Product: " , so i can get field Product before the product name.
I've tried to use Apply to each -> current item -> various ways to find 3rd occurrence and replace it, but can't succeed.
Any suggestion?
You should be able to loop through each item and perform a simple replace expression like thus ...
replace(item(), split(item(), ' | ')[3], concat('Product: ', split(item(), ' | ')[3]))
That should get you across the line. Of course, I'm basing my answer off the limited information you provided.

How to display the title of a data column in code.org app lab?

Does anyone know how to do this? I have tried everything I could think of in terms of how it could be stored as a variable, but I don't know what to do.
The title of a column is shown as its key name. For example, this:
| id | value |
| -- | ----- |
| 1| 6 |
is shown as this:
{
id: 1,
value: 6
}
The column name in this case is value. All you have to do is just put "value" (or whatever column name you're using) next to where you're showing the cell content.

Data Driven Testing Nightwatch

I am currently working on deciding a tool for automation an app on react/redux platform.
Most of the scenarios that I have in the app is possible to automate using nightwatch.
There are certain test cases or scenarios which repeat itself for different data sets.
For eg.
Steps to be executed:
Login to the application
Enter search criteria Step
Enter Color 1, Color 2, Color 3
Save and Validate
Test Data:
|UserName|Password|Search Criteria|Color 1|Color 2|Color 3|
-----------------------------------------------------------------------------
|abc | abc | search 1 |red | | |
|abc | abc | search 1 | |green | |
|abc | abc | search 2 |grey |white | |
|abc | abc | search 3 |white |black | yellow|
I have to execute the same set of code/steps multiple times depending the number of rows of test data we have.
I tried reading a lot of documentations but could not find any package which supports this type of automation in nightwatch.
Please help. Please do let me know if you need any more information.
Thanks & Regards,
Mukesh Panda
My suggestion is to place the test data in a JSON file and read it in your testpage file. and call it from testfile. something like,
loginPage.js contains
setCredentials : function (username, password) {
browser.setValue('#username', username);
browser.setValue('#password', password);
}
module.exports=loginPage;
and call the function in your test file like
loginTest.js contains
testData = require('testData.json');
loginPage = require('loginPage.js');
login = new loginPage(browser);
login.setCredentials(testData.username, testData.password);
something like this you can achieve it...

Ruby split pipes in regex

I have put the data from a file into an array, then I am just staying with the data I want of that array which looks like follows:
Basically what I want, is to access each column independently. As the file will keep changing I don't want something hard coded, I would have done it already :).
Element0: | data | address | type | source | disable |
Element1: | 0x000001 | 0x123456 | in | D | yes |
Element2: | 0x0d0f00 | 0xffffff | out | M | yes |
Element3: | 0xe00ab4 | 0xaefbd1 | in | E | no |
I have tried with the regexp /\|\s+.*\s+\|/it prints just few lines (it removes the data I care of). I also tried with /\|.*\|/ and it prints all empty.
I have googled the split method and I know that this is happening it is because of the .* removing the data I care of. I have also tried with the regexp \|\s*\| but it prints the whole line. I have tried with many regexp's but at this moment I can't think of a way to solve this.
Any recommendation?
`line_ary = ary_element.split(/\|\s.*\|/)
unless line_ary.nil? puts line_ary`
You should use the csv class instead of trying to regex parse it. Something like this will do:
require 'csv'
data = CSV.read('data.csv', 'r', col_sep: '|')
You can access rows and columns as a 2 dimentional array, e.g. to access row 2, column 4: data[1][3].
If for example you just wanted to print the address column for all rows you could do this instead:
CSV.foreach('data.csv', col_sep: '|') do |row|
puts row[2]
end
I'd probably use a CSV parser for this but if you want to use a regex and you're sure that you'll never have | inside one of the column values, then you want to say:
row = line.split(/\s*\|\s*/)
so that the whitespace on either side of the pipe becomes part of the delimiter. For example:
> 'Element0: | data | address | type | source | disable |'.split(/\s*\|\s*/)
=> ["Element0:", "data", "address", "type", "source", "disable"]
> 'Element1: | 0x000001 | 0x123456 | in | D | yes |'.split(/\s*\|\s*/)
=> ["Element1:", "0x000001", "0x123456", "in", "D", "yes"]
Split together with strip might be the easiest option. Have you tried something like this?
"Element3:...".split(/\|/).collect(&:strip)

Using Selenium IDE, how to get the value of dynamic variable

i'm using selenium ide 2.8 and i'm trying to store values please find my below commands:
store | ayman | val1
store | 1 | n
store | val${n} | e
how to echo the value of e which is ayman? when i try :
echo | ${e}
i got echo | val1
what is the issue with my commands?
Thanks
From what you've done there the value of 'e' is not ayman, you have stored ayman as the variable 'val1'. I'm not 100% what you're trying to do here but it looks like you're trying to store 2 individual variables and then combine them as one as well. If that is the cast then what you'd need is this
store | ayman | val1
store | 1 | n
store | ${val1}${n} | e
in which case:
val1 = ayman
n = 1
e = ayman1
It sounds like you are trying to force an array type structure? val[1], val[2]? Because what you want e to be is ${val${n}} right? Except that doesn't work. you could do this in javascript though (with storeEval): storeEval storedVars['val'+storedVars['n']] final

Resources