javascript - Verify an element is not existing using webdriver and selenium - Stack Overflow

I'm using WebdriverIO and selenium-standalone to write automated tests that will verify that vario

I'm using WebdriverIO and selenium-standalone to write automated tests that will verify that various parts of our user interface are working.

I need to verify that an element is not present on the page. For example, our system allows staff to track various types of resources that we are referring clients to. If a staff member accidentally adds the wrong resource, they can delete it, and I want to verify that the resource was actually deleted and is not present on the page.

WebdriverIO has an .isExisting() property, but no way to check if something is not existing (or not visible/present). I could also use Chai assertions to figure this out, but haven't delved into that world yet.

Here's a snippet of my code:

it('I can delete a resource from a need', function() {
    return driver
    .moveToObject('spanx-tasklist-task') // Hover mouse over resource
    .click('div.referral-controls a.btn.dropdown-standalone') // Click Resource drop-down
    .click('div.referral-controlsx-dropdown-menu-selected li > a') // Delete Resource
    .pause(2000);
    // Need to Verify that resource was deleted here

Any advice? Let me know if you need more information.

I'm using WebdriverIO and selenium-standalone to write automated tests that will verify that various parts of our user interface are working.

I need to verify that an element is not present on the page. For example, our system allows staff to track various types of resources that we are referring clients to. If a staff member accidentally adds the wrong resource, they can delete it, and I want to verify that the resource was actually deleted and is not present on the page.

WebdriverIO has an .isExisting() property, but no way to check if something is not existing (or not visible/present). I could also use Chai assertions to figure this out, but haven't delved into that world yet.

Here's a snippet of my code:

it('I can delete a resource from a need', function() {
    return driver
    .moveToObject('spanx-tasklist-task') // Hover mouse over resource
    .click('div.referral-controls a.btn.dropdown-standalone') // Click Resource drop-down
    .click('div.referral-controlsx-dropdown-menu-selected li > a') // Delete Resource
    .pause(2000);
    // Need to Verify that resource was deleted here

Any advice? Let me know if you need more information.

Share Improve this question edited Dec 14, 2017 at 14:48 iamdanchiv 4,1124 gold badges38 silver badges42 bronze badges asked Mar 25, 2015 at 17:43 RochelleRochelle 1611 gold badge1 silver badge4 bronze badges 2
  • There are lots of solutions, some are listed to the right of your post under the heading Related. Did you try any of those? – SiKing Commented Mar 25, 2015 at 18:08
  • I did take a look at them, but I had a hard time finding the right solution, probably because I'm fairly new at this and mainly only familiar with javascript. – Rochelle Commented Mar 25, 2015 at 18:22
Add a ment  | 

4 Answers 4

Reset to default 6

You can waitForExist with the reverse option set to true.

.waitForExist( '[id$=OpenNeedsPanel] div.modities', 500, true )

I was able to verify that an element didn't exist on the page like this:

.isExisting('[id$=OpenNeedsPanel] div.modities').should.eventually.equal(false);

you can simply use the below mentioned line of code

int temp=driver.findElements(By.xpath("your x-path expression")).size();

you can even replace your xpath locator with your other locators as well like id,class,link etc.

Now, if the value of temp>0, it means , your element exists

You can refer https://webdriver.io/docs/api/element/waitForExist.html

Wait for an element for the provided amount of milliseconds to be present within the DOM. Returns true if the selector matches at least one element that exists in the DOM, otherwise throws an error. If the reverse flag is true, the mand will instead return true if the selector does not match any elements.

resource.waitForExist(1000, true);

where 1000 is the timeout in ms.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743769126a4504047.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信