Selenium使用IE驱动程序循环确认弹出窗口

时间:2016-02-22 11:14:32

标签: selenium

我正在尝试自动化包含多个网络元素的流程。点击每个网络元素,它会弹出确认提示&需要接受这个确认。 这里的问题是,代码在它被攻击之后工作了5,6个元素。分享以下代码,

int number=Integer.parseInt(str1[10]);
int n;
System.out.println(number);
for( n = 1 ; n <= number ; n++)
    {
     try
      {
       driver.findElementByXPath("//div[contains(@class,'groupbox')]/div[contains(@class,'groupboxContent')]/table/tbody/tr/td[4]/span[contains(@class,'resourceActions')]/a[1]/img[contains(@title,'Undo check out')]").click();
       Alert alert=driver.switchTo().alert();
       driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
       alert.accept();
    }
    catch(NoAlertPresentException e)
    {

    }
    catch(UnhandledAlertException e)
    {

    }

请协助。

1 个答案:

答案 0 :(得分:0)

试试这个,想法是等待警报

var TARGET = process.env.npm_lifecycle_event;
var ROOT_PATH = path.resolve(__dirname);
var APP_PATH = path.resolve(ROOT_PATH, 'app');
var BUILD_PATH = path.resolve(ROOT_PATH, 'dist');

process.env.BABEL_ENV = TARGET;
var common = {
    entry: APP_PATH,

    output: {
        path: BUILD_PATH,
        filename: 'bundle.js'
    },

    module: {
        loaders: [
            {
                test: /\.jsx?$/,
                loaders: ['babel'],
                include: APP_PATH
            },
            {
                test: /\.svg$/,
                loader: 'url-loader?limit=8192',
                include: APP_PATH
            },
            {
                test: /\.png$/,
                loader: 'url-loader?limit=8192',
                include: APP_PATH
            },
            {
                test: /\.ico$/,
                loader: 'url-loader?limit=8192',
                include: APP_PATH
            }
        ]
    },

    plugins: [
        new HtmlWebpackPlugin({
            title: 'foobar',
            template: path.resolve(APP_PATH, 'index.html'),
            favicon: path.resolve(APP_PATH, 'images', 'favicon.ico')
        })
    ]
};

if (TARGET === 'start' || !TARGET) {
    module.exports = merge(common, {
        devtool: 'eval-source-map',
        module: {
            loaders: [
                {
                    test: /\.scss$/,
                    loaders: ['style', 'css', 'sass'],
                    include: APP_PATH
                }
            ]
        },
        devServer: {
            historyApiFallback: true,
            hot: true,
            inline: true,
            port: 3000,
            progress: true
        },
        plugins: [
            new webpack.HotModuleReplacementPlugin()
        ]
    });
}