Home > OS >  An alert can be accepted when loading page with selenium on internet explorer?
An alert can be accepted when loading page with selenium on internet explorer?

Time:10-02

I'm trying to get an url with selenium and node.js, but when the site has an alert I can't accept it on Internet Explorer.

index.js

    require('iedriver');
    const express = require('express');
    const webdriver = require('selenium-webdriver');
    let ie = require('selenium-webdriver/ie');
    function start(params) {
        start_server();
        let options = new ie.Options();     
          options.ignoreZoomSetting(true);
    
        let driver = new webdriver.Builder()
        .forBrowser('internet explorer')
        .withCapabilities(options)
        .build();
    
        let site="http://127.0.0.1:3000/";
        driver.get(site)
        .then(()=>{
            return driver.wait(webdriver.until.alertIsPresent(),10000)
            .then(()=>{
                let alert = driver.switchTo().alert();
                return alert.accept()
                console.log("go on");
            })
        })
        ;
    }
    const start_server=()=>{
    
        const app = express();
        const PORT = 3000;
      
        app.use(express.static('static'));
            
        app.get('/', function(req, res){
          let options = {
            root: path.join(__dirname "/../static/")
          };
          
          let fileName = 'index.html';
          res.sendFile(fileName, options, function (err) {
            if (err) {
              log(err);
            } else {
              console.log('Sent:', fileName);
            }
          });
        });
        
        app.listen(PORT, function(err){
          if (err) console.log(err);
          console.log("Server listening on PORT", PORT);
        });
          
      };
      start();

The site to open has an alert when page is loading, like this:

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="loading.js"></script>
    <title>Document</title>
</head>
<body>
       
</body>
</html>

loading.js

alert("accept before start");

This has to work on Internet Explorer.

When running , after 5 minutes it shows this

UnhandledPromiseRejectionWarning: TimeoutError: Timed out waiting for page to load.
at Object.throwDecodedError (C:\d\adhoc\node\copyimgwz\node_modules\selenium-webdriver\lib\error.js:517:15)
    at parseHttpResponse (C:\d\adhoc\node\copyimgwz\node_modules\selenium-webdriver\lib\http.js:642:13)

and stops like this

blocking alert on ie with selenium

Please, any idea how to accept that alert with selenium?

EDIT

I found out a solution, adding this line it's already working fine

options.introduceFlakinessByIgnoringProtectedModeSettings(true);

CodePudding user response:

I was able to make it work, adding this line

options.introduceFlakinessByIgnoringProtectedModeSettings(true);

in this section

let options = new ie.Options();     
options.ignoreZoomSetting(true);
options.introduceFlakinessByIgnoringProtectedModeSettings(true);

Aparently, On internet explorer you need to activate this characteristic to let you work.

  • Related