Balaji
Balaji

Reputation: 53

Making the web page to wait to load to identify the frame id

The js program which i wrote in the node.js is:

 var webdriver = require("selenium-webdriver");

    function createDriver() {
    var driver = new webdriver.Builder()
    .usingServer('http://localhost:4444/wd/hub')
    .withCapabilities(webdriver.Capabilities.chrome())
    .build();
    driver.manage().timeouts().setScriptTimeout(900000);
    return driver;
    }
var driver = createDriver();
driver.get('https:webpage-url');
driver.findElement(webdriver.By.name('USERNAME')).sendKeys('abcd');
driver.findElement(webdriver.By.name('PASSWORD')).sendKeys('pswd');
driver.findElement(webdriver.By.id('button')).click();
driver.findElement(webdriver.By.name('ABCD')).sendKeys('abcd');
driver.findElement(webdriver.By.id('button')).click();
driver.findElement(webdriver.By.name('DEPRT')).sendKeys('DEPT)');
driver.findElement(webdriver.By.id('abutton')).click(); 
driver.manage().timeouts().implicitlyWait(1000000);
driver.switchTo().defaultContent();
driver.switchTo().frame("frameid");
driver.findElement(webdriver.By.id('pbutton')).click();

I tried using implicitlyWait function before calling the frame element but it doesn't wait and the error NoSuchFrameError getting displayed.

Also i used only driver.wait(10000) before calling the iframe element but the it says timedout instead of executing the remaining steps. Please help me on this

Upvotes: 0

Views: 82

Answers (1)

Surya
Surya

Reputation: 4536

You need to use explicit wait, as explained here. Then your script will wait for that particular "frameid" to display, before switching to it.

Edited: Added sample code:

driver.wait(function() {
            return driver.findElement(webdriver.By.id('frameid')).isDisplayed();
        }, 30);

Upvotes: 1

Related Questions