I'm checking a checkbox status and hope to receive True or False.
Here is checkbox element in DOM (unselected by default):
<input type="checkbox" value="on"> </input>
If it is selected, the element in DOM will be changed to
<input type="checkbox" value="on"> ::after </input>
So, I use the following css to detect the checkbox when it is selected:
locator = by.css("div[class*='EchoFilterBar'] label[class*='EchoCheckbox']>input:checked");
Suppose that the checkbox is unselected, the locator will be non-existing in DOM and isPresent() should return to false. However, it does not work like that. when the locator not existing in DOM, protractor keeps looking the element until timeout.
element(locator).isPresent()
.then((value) => {
expect(value).toBe(false)
});
P/S: isPresent() works okay in true case, i.e, if xpath existing in DOM it returns to True correctly.
Hi @kms-loantran
If checked your setup and created this script
describe('Test isPresent is working correct', () => {
it('should not fail when an element is not presetn', () => {
browser.ignoreSynchronization = true;
browser.get('https://facebook.github.io/react/');
// Added the sleep just to show the automation is working
expect($('#todoExample').$('ul li').isPresent()).toBe(false);
browser.sleep(3000);
$('#todoExample').$('input').sendKeys('Add a todo');
browser.sleep(3000);
$('#todoExample').$('button').click();
browser.sleep(3000);
expect($('#todoExample').$('ul li').isPresent()).toBe(true);
browser.sleep(3000);
});
});
When you run this with a basic config you will see it works.
npm run test.example
> [email protected] test.example /Users/wswebcreation/protractor
> node ./bin/protractor example/conf.js
(node:88697) DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
[08:05:44] I/launcher - Running 1 instances of WebDriver
[08:05:44] I/hosted - Using the selenium server at http://localhost:4444/wd/hub/
Started
.
1 spec, 0 failures
Finished in 15.077 seconds
[08:06:02] I/launcher - 0 instance(s) of WebDriver still running
[08:06:02] I/launcher - firefox #01 passed
I think your problem is not with isPresent(), but with the way you are implementing the isPresent() in a expect. You can just use it in the expect without resolving it first.
Can you verify my script on your machine if it works. If it works then alter you expect to the above and run it again.
Hi @wswebcreation,
I run your script but still meet the issue I reported. It throws an error "A Jasmine spec timed out. Resetting the WebDriver Control Flow." after it try to find element not exist in DOM until timeout.
Anw, thanks for your comment :)
Can you please post your config file and your script here?
this is my script:
browser.ignoreSynchronization = true;
browser.waitForAngularEnabled(false);
describe('Verify "Show unassigned items only" checkobx status', () => {
it('"Show unassigned inventory items only" checkbox is unselected', (done) => {
const chkShowUnassignedItemSelection = element(by.css("div[class*='EchoFilterBar'] label[class*='EchoCheckbox']>input:checked"));
chkShowUnassignedItemSelection.isPresent()
.then(bool => expect(bool).toBe(false))
.then(() => done());
});
});
and your config please ;-)
Hi @wswebcreation,
I've just run my script again from my conf.js by calling "protractor conf.js" then I see that isPresent() works perfectly.
I guess the issue I met before is that I used seleniumPort =5548 (instead of 4444) and grunt file to run my script. I'm not sure whether it causes the issue or not. I'll investigate it and inform you when I figure out the root cause.
Thanks for your nice help :)
Hi @kms-loantran
Tnx for the feedback. I'm gonna close this for now, also because it is a local setting. If you have an other issue feel free to add it.
By the way, if edited your posts for readability with your code example. Are you familiar with Markdown? If not, you can find some info here
hey guys, i need some help whit this issue.
i'm trying to test if an element is not present whit this function:
Then(/^la opci贸n Eliminar no se encuentra$/, function (callback) {
browser.waitForAngular().then(function() {
page.matRowArray.isPresent().then(function () {
page.productInput.isPresent().then(function (button) {
expect(button).to.equal(false);
browser.sleep(1000).then(function () {
console.log('no se puede eliminar el articulo');
callback();
});
});
});
});
});
but get no response from the browser or the GUI say that :
(node:88992) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): NoSuchElementError: No element found using locator: By(css selector, *[name="productInput"])
this is driving me crazy, please helpme!!
@flucena89 You are more likely to get a response if you format your code properly.