Selenium IDE, selecting muliple text using same class - selenium-ide

I have a page with lots of text using the same class. I am wanting to select and store all the text with that same class. Is this possible? All advice & comments appreciated!
I have HTML code like this:
<p class="foo">Some sample text</p>
<p class="foo">Some more sample text</p>
I have tried this:
<tr>
<td>storeText</td>
<td>//p[#class=foo']</td>
<td>var1</td>
</tr>
I expected var1 to be:
Some sample text
Some more sample text
Alternatively do I need to set up a while statement and gather each individually?
This page talks about a similar exercise, but uses Selenium for Python: Get the text from multiple elements with the same class in Selenium for Python?

//gather all p[class=foo]
List<WebElement> ele = driver.findElements(By.cssSelector("p.foo"));
Iterator<WebElement> iter = ele.iterator();
// initialize array, map, whatever
While(iter.hasNext()) {
// insert text into map
// print to log
// store in array
//whatever you need
var.add( iter.next().text() );
}

I didn't get to try out the answer from #bcar because I am not a javascript expert nor am I sure I could put the answer into IDE. I found another way however. I discovered that the text is stored in tables, so I am using the following code to extract the entire table (which includes the text I need).
<tr>
<td>storeText</td>
<td>//div/h2[text()="Elements and Performance Criteria"]/following::table</td>
<td>Content</td>
</tr>
Now I have to work out how to replace the new lines with as this is plain text. Another question for stackoverflow! Thanks.

Quite easy:
Just loop through the stored elements.
Whenever you use find_elements_by_class_name, it returns the list of selenium web elements. Hence you just need to iterate with a loop, like this.
names = driver.find_elements_by_class_name("_xEcR")
for i in names:
print(i.text)

Related

How to do a regexp in a waitForPopUp Command in Selenium IDE?

I have popups with this name structure:
static_dynamic_static
The dynamic part changes each time I log in so my test cases fail each time. I thought about solving the problem with a regular expression like this:
Command: waitForPopUp
Target: regexp:static_.+_static
But this doesn't work. What do I do wrong? Is this even working. If not, is there another way to solve this problem?
From my experience you don't need to declare it as a regex within the target field, you should just be able to have the target as:
static_*_static
and that should do it
If you've got only one popup window you can use null as a target and test will take the first popup:
waitForPopup | null
The other option is to get dynamic part before popup opening. It is very likely that the dynamic part could be retrieved from the page. If so you can get it using storeEval, and than use like:
waitForPopup | javascript{'static'+storedVars['dynamic']+'static'}
If you can't store the dynamic part please provide an html of your page or only the part where the dynamic part mentioned.
I see that theoretically it could be possible to get all the names of your windows and than to use pattern in a loop to get the one.
Also (theoretically) it is possible to expand default waitForPopup function.
But the second way and especially the first are much cheaper.
The best way to handle this might be to run a snippet of javascript to handle this:
<tr>
<td>storeEval</td>
<td>var myRe = new RegExp("^prefix.+", "g"); var mywin; windows=selenium.getAllWindowNames();for (i = 0; i < windows.length; i++) { if(myRe.test(windows[i])) { mywin=windows[i]} }; mywin;</td>
<td>x</td>
</tr>
<tr>
<td>selectWindow</td>
<td>name=${myWindow}</td>
<td></td>
</tr>
That javascript isn't fully function (no null checking) but should help get you on the right track.

Is it possible to find and store element's location by text in selenium ide?

I need to create the element and then delete it. Is there a way to find the element by it's text after it was created?
The xpath of the element is //div[#id='mif-tree-6']/span/span[3].
You can use xpath for it for example. Like:
//div[#id='mif-tree-6']//span[contains(text(),'your_text_here')]
UPDATE
Please provide an example of your html. It is possible to find a parent of your element with xpath and after that to find all the childs. For example your html =
<div id='lol'>
<div>first_item</div>
<div>second_item</div>
<div>third_element</div>
</div>
You get an array of elements with xpath =
//div[contains(text(),'first_')]/../div
So you can do something like:
click | //div[contains(text(),'first_')]/../div[2]
BUT if there are a lot of brothers-elements to find by text of one sibling it will be necessary to use loop to get every of them.
Once again. If you will provide full information about what are you doing and an example of your html it will be much easier to suggest.

How to select a DOM element in JavaScript?

I want the user to be able to select the contents of a element by clicking it once. The code would look like this:
<div onclick="this.xyz()">...</div>
The question is: what method goes where I wrote xyz? I've searched for things like "DOM select object," but the answer is a needle hidden in a haystack of irrelevant hits (or not).
Basically you'd want:
<div onclick="var contents = this.innerText;">foo bar</div>
which would set contents equal to foo bar. Of course, this isn't exactly cross-platform compatible. Firefox expects .textContent instead of .innerText. If you're not opposed to using jquery, then
<div onclick="var contents = $(this).text()">foo bar</div>
would do just as well and be cross-platform.

Meteor Handlebars templates: switching from text to input

One part of my meteor application is a semi-collaborative table where users can edit different rows at the same time. When a user is editing a row, the static text values need to switch to input boxes so that the values can be edited and then saved. I would like a template/helper to do this, essentially I want:
<td>
{{#if iAmEditing}}
{{foo}}
{{else}}
<input type="text" name="foo" value="{{foo}}">
</td>
except that there are several columns with different values of "foo" and I don't want to copy and paste this several times. What's the right way to approach this with templates and helpers?
Another approach might be to use the HTML5 contenteditable attribute. Either way, what is the right way to template these values with handlebars?
You should be able to integrate with Bootstrap Editable
For reference, an answer to the original question...
As of today, handlebars partials can't accept anything other than a context argument, but helpers can. Hence. you can define a helper that sets up the context for the template:
Coffeescript:
Handlebars.registerHelper "eventCell", (context, field, editable) ->
return new Handlebars.SafeString(
Template._eventCell
_id: context._id
field: field
value: context[field]
editable: editable
)
Template:
<template name="_eventCell">
<td><div data-ref="{{field}}" class="{{#if editable}}editable{{/if}}">
{{value}}
</div></td>
</template>
Then, I just use the following to render each field:
{{eventCell this "province" iAmEditing}}
I ended up integrating with bootstrap editable, so the template is a little different than my original question. Also, I'm not sure if this is the best way to do it, but it's a lot cleaner than what I had before.
meteor-editable is a new project implementing something like x-editable, but nicely integrated with Meteor reactivity. Unfortunately inline editing is not supported yet (you have to use a popover the way it's set up now).

Simple paragraph break

I am trying to make a simple paragraph break in my text file (name.js) so that when the iphone pulls the information (name.js) there is not one big run on paragraph. I have looked and looked and cannot find this information can you help me project is due at this time...
try something like this in the javascript:
var pageBreak = document.createElement("/p");
document.getElementsByTagName("tagToInsertBreakAfter")[0].appendChild(pageBreak);
I am away from my machine so i cannot check but try a \n or \r\n
Well it had to be one or the other it'
<br />
i just hacked a widget and tried it. By the way i am assuming you are doing some like the following
// localised strings
var backString_01 = "World Second <br />offers unbeatable exchange rates and exceptional service for foreign exchange and international payments";
then outputting to the document with
document.getElementById('services_headline').innerHTML = backString_01;
With the element in the html something like ....
<div id="services_headline" apple-part="com.apple.Dashcode.part.text" class="apple-text apple-no-children" apple-default-image-visibility="hidden" apple-text-overflow="ellipsis"></div>