单击页面上的按钮,直到所有内容都被删除 [英] Click buttons on page until all will be removed

查看:111
本文介绍了单击页面上的按钮,直到所有内容都被删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的场景:在一个页面上,我有多个按钮。单击按钮后,将重新加载页面而不单击按钮。

My scenario: On a page, I have multiple buttons. After button is clicked, page is reloaded without the clicked button.

我在实施正确解决方案时遇到问题。

I have a problem with the implementation of a proper solution.

目前我有这样的事情:

let selector = 'selector for All button on page';
let buttons = browser.$$(selector);

for (int i = 0; i < buttons.length; i++) {
    let button = browser.$(selector);
    button.moveToObject();
    button.waitForVisible();
    button.click();
    browser.waitToVisible(elementAfterPageRefresh);
}

第一次迭代后出现问题。有时它只能移动到按钮,有时脚本甚至没有点击第二个按钮。

The problem occurs after the first iteration. Sometimes it works by only moving to the button, sometimes the script does not even click the second button.

用webdriverio解决我的问题的正确方法是什么?

What is the proper way to solve my problem with webdriverio?

推荐答案

运行代码后,是否还可以从控制台提供错误回溯?
我认为你正面临臭名昭着的 陈旧元素参考...... 错误。

Can you also provide a error traceback from the console after running your code? I presume you are facing the notorious "Stale element reference..." error.

首先, WebdriverIO 驱动程序以及 WebdriverJS 之一(其前身)将始终丢失对浏览器之后查询的元素/元素的引用(元素ID)执行页面重新加载。

First of all, a WebdriverIO driver, as well as a WebdriverJS one (its predecessor) will always lose the reference (element ID) to previously queried element/elements after the browser executes a page reload.

所以根据 Christian Bromman @ ChristianB ),你必须做的事情是:

So according to Christian Bromman (@ChristianB), you will have to do something along the lines of:

runner
.init()
.url('https://www.google.dk/search?q=burrito')
.getText(".r").then(function(res){ // given `.r` is the <a /> tag on google search page
    res.value.forEach(function(elem){
        console.log(elem);
        clicks.push(
            runner
                .click('=' + elem.ELEMENT) // use link text selector to query the element again
                .pause(5000)
                .back()
                .pause(2000)
        );
    });

    return q.all(clicks);
});

我认为这仅用于培训目的,因为我无法理解为什么每次触发都会点击一系列按钮页面刷新。 :)

I presume this is only for training purposes as I cannot understand why clicking a series of buttons would each trigger a page refresh. :)

这篇关于单击页面上的按钮,直到所有内容都被删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆