How to check that data selector is not on the screen using puppeteer - dom

I need to check that data-selector is visible only in case I press one button. On front end it works that one button runs some code and there appeare one fa-lock icon. When I press another button than this icon disappeare. When I try to inspect element in console for developer I see that using this:
document.querySelectorAll('[data-selector="private-inbox-lock-icon"]')
there is empty NodeList with length 0 when icon is not on the screen and NodeList is e.g. NodeList [i.fal.fa-lock.lock-icon] with length 1 whene icon is on the screen. So this is proof that it works. But I am not able to make chai assertion condition to check this in backend.
I get all selectors from the screen
const lockIcons = await
World.page.$$('[data-selector="private-inbox-lock-icon"]');
But I am not able to set up condition when selector is not on the screen cause await alway returns me an array of elements. ElementHandle type. So this is alway full of data...
expect(lockIcons).to.not.be.empty; - true when Icon on the screen
expect(lockIcons).to.be.empty; - doesn´t work cause lockIcons is not empty anytime.......
How to set up condition when lockIcons is always not null, no empty even if data-selector is not on the screen... I don´t just got it..

you might take a look at waitForSelector method, in case there are CSS properties like display
const node = await page.waitForSelector('[data-selector="private-inbox-lock-icon"]', { visible: true });
it will return false when display property will be set to none
this should work if there's only one element matching your selector
Other scenario:
if you expecting element to be removed from DOM then simple
await page.$('[data-selector="private-inbox-lock-icon"]') will return null because there's no element matching selector
then from chai docs:
expect(node).to.be.null;

Related

Code to click a radio button does not work the second time in my Protractor script

I am calling a function twice to execute a piece of code in my protractor script. A snapshot of the code of my function that is failing when called the second time is below. sessionNo is an argument passed to this function. It could be either 0 or 1. Depending on the value of this argument, either the radio button with index 0 will be selected or the radio button with index 1 will be selected.
function sessionBegin(sessionNo)
{
element.all(by.repeater('type in types')).all(by.css ("input[type='radio']")).isPresent(). then(function()
{
var sessionType = element.all(by.repeater('type in types')).all(by.css ("input[type='radio']")).get(sessionNo);
sessionType.click();
});
}
This code works great when this function is called for the first time. But when it is called the second time with a different value for sessionNo, it fails with "Failed: element not visible" error. I can't figure out why is the above code unable to locate the same element for the second time as it did for the first time with the exact same code.
It depends on your application code, may be your element becomes invisible between it's found and click action, or it's not visible yet. For the first case you should investigate what happens in application side, for second case (if it's not visible yet), you can wait until it became visible, for example: browser.wait(EC.visibilityOf(element), 5000, Element not visible: ${element.locator()});
it will wait for for element 5 seconds.

Cannot click ListViewCell with null value

The tests I am developing access the DataGrid cells the following way:
window.Get<ListView>(gridName).Rows.First().Cells.First()
Then clicking a cell with UIItem.Click() method works fine, unless the cell is bound to a null value. In such a case, I get an exception:
Failed to click on ListViewCell. AutomationId:, Name:, ControlType:text, FrameworkId:WPF, bounds empty
Which makes sense, as apparently, an AutomationElement related to that cell is a TextBlock of 0 boundaries.
Is there some possible workaround to click such a cell so the tests work?
What seems to be a good enough workaround is the following:
this.window.Mouse.Location = Point.Subtract(cellToClick.ClickablePoint, new Vector(12, 6));
this.window.Mouse.Click(this.window.Mouse.Location);
So I just set the mouse location using property TestStack.White.UIItems.Mouse so it is situated right above the cell, then click.

Wrap a list of WebElements and present as a single WebElement

I am automating testing of a response web app and have an issue with multiple elements on the page with the same #FindBy selector where only one is visible at a particular screen resolution (in this case a logout button that 'moves' around the screen).
I could just get a list of webelements and click on the first visible, but I was wondering if I could do something smarter using html elements:
Given the following annotation
#FindBy(css = ".logoutButton")
MultiWebElement logoutButton;
When I call this method
logoutButton.click();
Then the MultiWebElement class will iterate over all elements that match the find by and call the click method on the first one that isDisplayed().
Unfortunately the decorator seems to want logoutButton to be of type List which defeats the purpose of creating the new class.
Can I do something like this, or is this outside the current scope?

PhoneGap + iOS Prevent default scroll action begins from input text field

I've faced up with the following problem:
I have a scroll area which contains list of input text fields.
I use
ontouchmove = function(e){ e. preventDefault(); }
to prevent global scroll of the page. It works fine except cases when gesture begins from input field.
How can I prevent global scroll of the page when first touch traps to the input field?
Thanks.
I believe you want to capture the touchmove event using the addEventListener function so that the even doesn't "bubble". Try this:
/* This code prevents users from dragging the page */
var preventDefaultScroll = function(event) {
event.preventDefault();
window.scroll(0,0);
return false;
};
document.addEventListener('touchmove', preventDefaultScroll, false);
this might help
the section "MORE SPECIALIZED SOLUTION" might be what you are looking for.

jquery .attr('alt','logo').css('display','none') not working !

I have the three following lines and the first two line gets all the images on the document and hides all, but then when I add the third line shows all the images.
What I need its to hide only the images with the attribute alt=minimize and alt=maximize but for some reason hides all the images.
$('img').attr('alt', 'minimize').css("display","none");
$('img').attr('alt', 'maximize').css("display","none");
$('img').attr('alt', 'logo').css("display","inline");
I am using IE7, but it should be compatible with IE6 and IE8.
Any help would be very much appreciated.
Thanks.
I'm thinking you are not using the attr function correctly, might you be looking for the attribute equals selector?:
$('img[alt=minimize]').css("display","none");
What you did with your code was,
Select all images
Change their alt attribute to 'minimize'
Hide them
Select all images
Change their alt attribute to 'maximize'
Hide them
Select all images
Change their alt attribute to 'logo'
Hide them
what you do: you take every img in document and set alt to logo and then set display: inline;.
Note, that attr('alt',string) doesn't filter all images to those with alt=string, but rather sets alt attribute to string on all images.
What you want to use is this:
$('img[alt="minimize"]').css...
$('img[alt="maximize"]').css...
$('img[alt="logo"]').css...
In the call $('img').attr('alt', 'logo').css("display","inline"); the "attr" doesen't filter the set of dom elements You catch with $("img").
If you want to hide everithing but not the image with the attribute 'alt' = 'logo' I think You can:
give it an Id of logo and then calling: $("img").not("#logo").hide()
from the jquery website:
hide():
The matched elements will be hidden
immediately, with no animation. This
is roughly equivalent to calling
.css('display', 'none'), except that
the value of the display property is
saved in jQuery's data cache so that
display can later be restored to its
initial value. If an element has a
display value of inline, then is
hidden and shown, it will once again
be displayed inline.
and
attr( attributeName )
Returns: String
Description: Get the value of an
attribute for the first element in the
set of matched elements.
If instead you want to hide all the maximize and minimize images (both share the "imize" part of the attribute):
$(parentElement).find("img[#attr $= '*imize']").hide()
OP is referring to
http://dev.w3.org/csswg/css3-values/#attr
alt I think is simply a string type, not "logo" whatever that is, that is not a data type.
try that. in fact, you can look up alt in the html5 img
http://www.w3.org/TR/html5/the-img-element.html#the-img-element
http://www.w3.org/TR/html5/the-img-element.html#attr-img-alt
http://www.w3.org/TR/html5/the-img-element.html#alt
(in order of reference clicking, last one is the target)
even if this isn't the exact answer (it should be), it should be a step in the right direction.
I am actually trying myself to figure out how to reference a css property within css with attr() - it's mentioned within the top URL. if I had my druthers, I could be using css calc() along with it, but that's draft. maybe I can get it to work...