question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] isPresent() does not return false when element not found in DOM

See original GitHub issue

Bug Report:

  • Node Version: 8.1.4, 6.9.1, 6.9.2
  • Protractor Version: 5.1.2
  • Angular Version: non-angular. we use react
  • Browser(s): chrome 59.0
  • Operating System and Version: wins10

Description:

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.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
flucena89commented, Apr 6, 2018

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!!

0reactions
demisxcommented, Sep 18, 2018

@flucena89 You are more likely to get a response if you format your code properly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

element doesn't exist in the DOM, isPresent() should return ...
While isPresent() doesn't work properly if an element doesn't exist, we can use browser.executeScript instead. It works fine!
Read more >
isDisplayed Error No element found using locator instead of ...
I have a method isElementDisplayed with element.isDisplayed call inside. It is throwing No ... ElementFinder) { return element.
Read more >
Guide - Nullable Versus isPresent - UTAM
A getMyElement().isPresent() call returns true for an existing element or throws an error for a non-nullable absent element. The isPresent() call returns false...
Read more >
How to check if an element is present with protractor?
Checks whether the element is present on the page. It returns true if the element is present on the page or returns false....
Read more >
How to continue script when element is not found in selenium
Boolean isPresent = driver.findElements(By.yourLocator).size() > 0. This will return true if at least one element is found and false if it does not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found