Selenium IDE: How to count the number of lines in a text area? - selenium

I have this textarea where anyone can type/paste in multiple phonenumbers, with only one phone number entered per line. When this is saved, the numbers will then appear in a table listing all phone numbers for that user.
I am trying to create a test where I can count the number of phonenumbers that the user entered. I will use this number to compare the total number of phonenumbers before and after the user added them in the textarea
For example a user might type in 2 phonenumbers in the textarea:
123456789
102563987
StoreCSS and xpath count won't work in this case since the characters that a user types in won't be saved in the html.
I have tried storing the value that is typed in the textarea and splitting the lines, but I'm stuck there and not sure what to do next.
Any help will be most welcome. Thanks!

You can do this way. Say for example, stackoverflow's comment area is of textarea. Its css is:
textarea[name='comment']
I could able to do this:
String commentText = driver.findElement(By.cssSelector("textarea[name='comment']")).getText()
Then you can split the string using \n, like this:
commentText.split("\n").size()
is giving me the number of lines entered by the user.

Related

Is there a function in Archer that could draw a line separating two outputs in a single field?

I am trying to concatenate 2 outputs in calculated text field. But I would like to draw a line in between them or at least give them a heading, so that the users will be able to identify them easily. I could make different fields and have them calculated. But the requirement is to concatenate 15 fields into one field. So, I do not want to create 15 fields and write separate calcs. See below example
Example 1)
Hello, this is an example of what I am trying to explain with an example (o/p 1)
Hello, this is how I would like to present to the end users avoiding confusion (o/p 2)
As you see above, I was able to concatenate 2 o/p's, but I would like to draw a line. This one scenario that would work for me.
Example 2)enter image description here
Users Watch
Hello, this is an example of what I am trying to explain with an example (o/p 1)
Admin Watch
Hello, this is how I would like to present to the end users avoiding confusion (o/p 2)
As you see in 2nd example, I would like to put a heading for o/p 1 as "users watch" and "Admin Watch" for o/p 2, so that the users can differentiate it.
I have tried sub-string function for example 2, it looks 'OK' but it would be of more help if anyone has better solution.
The beauty of Archer is that you can use HTML in the calculation; providing that the calculated field is a text field and that its display is set as text area.
You can use the following calculation:
CONCATENATE("<H3>Header 1</H3>", [Field 1], "<H3>Header 2</H3>", [Field 2])

selenium issue:How to capture dynamic voucher number in a website

I have a website where two users (user15 and user16), user 15 creates a voucher which gets approved by user16. So in the home screen of user15 a voucher number is generated which is dynamic as shown in image below.I need to capture this voucher number generated for the one whose status is ""Processed" and then put it into the search filter of user16 homepage screen.How can i capture this dynamic voucher number ?
voucher number image
Your table template looks static. It is only the rows that are getting changes so you can write an xpath like below which would directly get you the voucher name:
//td[text()='Processed')]/preceding-sibling::td[colnumber of VoucherNubmer]
Please follow following steps mentioned below:
First select all elements from the table within the list.
Then using foreach loop compare the status of the element.
After that if(status=="Processed") then using getText() method print the value of the vochure number.

#Dblookup and formatting on web

I have been developing a web application using domino, therein I have dblookup-ing the field from notes client; Now, this is working fine but the format of value is missing while using on web.
For example in lotus notes client the field value format is as above
I am one, I am two, I am one , I am two, labbblallalalalalalalalalalalalalalalalalalaallllal
Labbbaalalalallalalalalalaalallaal
Hello there, labblalalallalalalllaalalalalalalalalalalalalalalalalalalalalalalala
Now when I retrieve the value of the field on web it seems it takes 2 immediate after 1. and so forth, I was expecting line feed here which is not happening.
The field above is multi valued field. Also on web I have used computed text which does db lookup from notes client.
Please help me what else could/alternate solution for this case.
Thanks
HD
Your multi-valued field has display options associated with it and the Notes client honors those. Obviously, your options are set up to display entries separated by newlines.
The computed text that you are using for the web does not have options like that and the field options are irrelevant because you aren't displaying the field. Your code has to insert the #Newlines. That's pretty easy because #DbLookup returns a list, and if you concatenate a list and a scalar, the scalar will be appended to each element of the list. (Look at the third example under "concatenation, pairwise" here to see what I mean.
The way you've worded your question is a little unclear to me, but what you need in your computed text formula is either something like this:
list := #DbLookup(etc,. etc.);
list + #Newline;
Or something like this:
multiValueFieldContainingListWithDbLookupResult + #NewLine;
I used #implode(Dblookupreturnedvalue;"");
thanks All :)

How to extract full prices with scrapy?

Hi i am trying to scrap e-commerce page, but cant get prices.
I have page with this lines:
<span class="price">255,<sup>99</sup>€</span>
<span class="price">255 €</span>
But i can't extracts all price to one line.
I tried:
response.xpath('//span[#class="price"]/text()').extract()
But it ignores text in <sup> tag...
What i am doing wrong? please help.
You need to add another slash before text. So it addresses ALL nodes.
response.xpath('//span[#class="price"]//text()').extract()
Text='255,'
Text='99'
Text='€'
You should put double splash instead of single one.
response.xpath('//span[#class="price"]//text()').extract()
This statement returns all text under the specified tag as list object.
Note that the returned list may have some useless elements just like empty or return carriage character.
So you can use regex if you want extract only price information.
response.xpath('//span[#class="price"]//text()').re(r'[\d.,]+')
The currency symbol was ignored.
['255,','99','255']
Finally if you want get 255.99 from the page
''.join(response.xpath('//span[#class="price"][1]//text()').re(r'[\d.,]+')).replace(",",".")
You get all products first.
Final code:
products = response.xpath('//*[#class="catalog-table"]//td')
for prod in products:
price = ''.join(prod.xpath('//span[#class="price"][1]//text()').re(r'[\d.,]+')).replace(",",".")
print price
Check source HTML. There is in the source:
I was searching for the same question for the whole day and find this answer perfect for this
response.xpath('//meta[#itemprop="price"]/#content').get()

Find correct table number (Selenium IDE)

I have this command here in Selenium IDE to store a text in a variable:
Command: storeText
Target: //div[#id='content-main']/form[2]/table[5]/tbody/tr[td[1][contains(text(), 'Purchase')]]/td[2]
Value: variableName
As you can see, in this command it looks in the first column of the 5th table and search for the line where it says "Purchase" and stores the string content from the second column.
The problem is this: table[5]
There are some times where this table is not always the 5th table. So, I'd like to know if there is some way to search for this String that I'm looking for, but without the table number, so the command would first find the table number, and then find the string I'm looking for.
To make it easier, here is the HTML source of the page I'm doing my tests:
http://txtup.co/e9KYB
I accept suggestions to maybe do it in another way, what I need is to store the Purchase Type value that is in this page.
Just change table[5] to table. The full XPath will then be:
//div[#id='content-main']/form[2]/table/tbody/tr[td[1][contains(text(), 'Purchase')]]/td[2]