Cypress: I have a issues geting a textBox "HELP!" - dom

I'm trying to get a textBox so in the code I added data-cy attribute:
<login.StyledInput
// eslint-disable-next-line jsx-a11y/no-autofocus
autoFocus={focus}
type={type}
value={value}
disabled={disabled}
onInput={onInput}
onKeyUp={onKeyUp}
data-cy={`${text}-textbox`.replace(/\s+/g, '-')}
/>
In the DOM it looks like this:
This add data-cy in all the textBox, the one I'm looking for is named data-cy=Password-textBox, at the begin, I use this to get it:
cy.get('[data-cy=Password-textbox]').eq(1);
I'm using eq(1) because is the second element with the attribute data-cy=Password-textBox but It didn't work, however, I used the code below and It worked:
cy.get('#other-form-animator > :nth-child(4) > .rs-input-group > [data-cy=Password-textbox]');
the problem is that my boss won't let me use the last one.
Does anyone know of a better-looking solution? and Why [data-cy=Password-textbox] doesn't work?

You are trying to get an element by css selector. That selector is a string, this to get a property - You should use double quotation marks for the property, which is a string within the string. You can literally copy paste it from the element in the inspect menu into this cy.get:
cy.get('[data-cy="Password-textbox"]').eq(1);

Related

Ionic2, ion-range custom content of the range pin

I am using ion-range with pin and steps. I get the current value in the range pin, but I want to add/append some text next to it.
So far in ionic API and docs I did not find a way to modify the content from the range pin, so I am thinking on maybe appending a span via the code, but so far I know to use .append() function from jQuery.
The html of the range pin is:
<div class="range-pin" role="presentation">1</div>
So I want to show it like:
<div class="range-pin" role="presentation">1 item</div>
I know it is a bit late but if anyone comes across this question, I have found the following solution:
HTML
<ion-range id="euroRange" debounce="250" pin="true" min="0" max="50" (ionChange)="formDidUpdate()" [(ngModel)]="price" color="secondary"></ion-range>
See how I added an id called euroRange to my ion-range element.
CSS
#euroRange {
.range-pin:after {
content: " €";
}
}
Inside of the euroRage id I added .range-pin:after which means that whatever I specify should be done directly after the normal content of the pin.
With content I added a space and the € symbol.
Here is the
result.
This was my solution.
Note: I put this inside ionViewDidEnter.
this._elementRef.nativeElement
.querySelector('.range-knob-handle')
.addEventListener('pointermove', function () {
const value = this.getAttribute('aria-valuenow');
this.querySelector('.range-pin').textContent = `${value} hours`;
});
So the main thing here is that the const value is the value selected on the range. After that you can do whatever you want with it and just set the textContent of the range-pin to fix the text.

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.

Angular-material. Autocomplete directive

I have some problem with autocomplete. And my question is: Can I send my own personally typed text instead object from autocomplete list?
When I send object from list to "person.eamil" it's ok, but
when I send normal text to "person.email" I get null instead my text.
Here is my HTML code:
<md-autocomplete
ng-model="person.email"
ng-disabled="false"
md-no-cache="true"
md-selected-item="person.email"
md-search-text-change="setPersonValidEmail(person, !innerForm.email.$error.email);"
md-search-text="searchText"
md-items="item in people"
md-item-text="item.email"
md-min-length="0"
placeholder="some#one.com"
ng-click="addOurPersonIfNecessary($index);"
name = "email">
<md-item-template>
<span md-highlight-text="searchText" md-highlight-flags="^i">{{item.name}}</span>
</md-item-template>
</md-autocomplete>
Md-selected-item here is expecting an object that is populated in people. Only then it can populate the auto complete. You can pass the text to md-search-text
I found solution. Try to use another autocomplete plugin like this:
https://github.com/ghiden/angucomplete-alt

How do I use Perl's Remote::Selenium::WebElement to verify the URL a hyperlink will take me to?

Seems like it should be straightforward but I can't seem to get to the bottom of it.
Here's the HTML I'm working with:
<li id="a" class="FILElevel3" onclick="changeMenu("b")">
<a onclick="stopBubble(event);" href="javascript:LinkPopup('/sub/URL.html')">Visible Text</a>
I'm able to find the element using XPaths:
my $returned_asset = $sel->find_element("//*[\#class='LINKlevel3']");
And I can verify this works because I'm able to extract the visible text from it:
my $returned_name = Selenium::Remote::WebElement::get_text($returned_asset);
I just can't seem to find the sequence to pull the HREF attribute from the element to put the link's URL into a verifiable string. Should I be able to do this using WebElement's get_attribute() method? I've tried variations on this:
my $returned_URL = $returned_asset-> Selenium::Remote::WebElement::get_attribute("a/href");
...where I've plugged in everything I could think of for that "a/href" string. What should go in there?
In the end I'd like to be able to put "javascript:LinkPopup('/sub/URL.html')" into a string and verify that my URL is in there.
have you tried
my $returned_asset = $sel->find_element("//*[\#class='LINKlevel3']/a");
my $returned_URL = $returned_asset->Selenium::Remote::WebElement::get_attribute("href");

How to use jQuery to search for text that contains a bracket "("?

I'm trying to use jQuery to locate all <a> tags that contain a piece of text in brackets so I can perform some manipulation on them.
However I'm struggling to even find these tags. And I am getting a javascript error:
"Syntax error, unrecognized expression: '(')"
When I try to use the following code:
jQuery("a:contains(' (')").css("text-decoration", "underline");
Presumably because the javascript doesn't like a ( within the contains function. Does anyone know a way around this?
Thanks in advance!
$('a').each(function(index){
if($(this).text().indexOf('(')!=-1){
$(this).css("text-decoration","underline");
}
});
This is not a performant solution but just a hint, iterate over every <a> get their text() and if they contain a ( underline them.
If your ( is not in between HERE() you could check for the href attribute and get it's value and look if in the value it contains (
Please check this
<script>
var sent = "(";
$("a:contains("+sent+")").css("text-decoration", "underline");
</script>