0
votes

Getting the following error while executing the below js. Please advise.

HTML:

<div id="iframeContainer">
<iframe class="selectedModulesIframe" frameborder="0" src="XXXXXX/?locale=en&amp;security={&quot;language&quot;:&quot;en&quot;,&quot;token&quot;:&quot;LYu1sFnCa6UHRTEs1Xsa3bs7&quot;,&quot;agentId&quot;:{&quot;id&quot;:&quot;SSHAIK&quot;},&quot;organisation&quot;:&quot;RAIL-NSWT&quot;,&quot;distributedContextID&quot;:null,&quot;securityModeCode&quot;:null}&amp;module=SCHEDULECHANGELIST" id="SCHEDULE1552627852125" name="SCHEDULE1552627852125" style="height: 519px; width: 1903px;">
</iframe>
</div>

<span id="w10" atdelegate="d6" class="xWidget" style="width:85px;margin:0px 0px 0px 10px;">
<a class="xLink_std" href="javascript:(function(){})()" tabindex="1&quot;">192429</a>
</span>

Here is my code:

browser.switchTo().frame(browser.driver.findElement(protractor.By.tagName('iframe'))).then(function(){
        console.log('Iframe switch')
        browser.driver.findElement(protractor.By.linkText("192429")).click().then(function(){
            console.log('action performed') 
        })

    })

Also try the below code:

browser.switchTo().frame(browser.driver.findElement(protractor.By.tagName('iframe'))).then(function(){
        console.log('Iframe switch')
        element(by.linkText('192429')).click();

})

Error response:

[16:49:46] I/launcher - Running 1 instances of WebDriver [16:49:46] I/hosted - Using the selenium server at http://localhost:4444/wd/hub Started Got the iframe Iframe switch [31mF[0m Failures: 1) Affected Passenger Notification Verify APR in Schedule Change UI Message: [31m Failed: no such element: Unable to locate element: {"method":"link text","selector":"192429"} (Session info: chrome=72.0.3626.121) (Driver info: chromedriver=2.46.628402 (536cd7adbad73a3783fdc2cab92ab2ba7ec361e1),platform=Windows NT 10.0.15063 x86_64)[0m Stack: NoSuchElementError: no such element: Unable to locate element: {"method":"link text","selector":"192429"} (Session info: chrome=72.0.3626.121) (Driver info: chromedriver=2.46.628402 (536cd7adbad73a3783fdc2cab92ab2ba7ec361e1),platform=Windows NT 10.0.15063 x86_64) at Object.checkLegacyResponse (C:\Users\sshaik\eclipse-workspace\Protractor_Orion\protractor\node_modules\selenium-webdriver\lib\error.js:546:15)

HTML:

2
From the code you posted that element you require is not within the Iframe. I assume that is an error in your question? - DublinDev

2 Answers

0
votes

Try the below one

const iframeLocator = browser.driver.findElement(by.css('iframe.selectedModulesIframe'));

   goToIFrame: function () {
        browser.switchTo().frame(iframeLocator );
    },

    goToDefault: function () {
        browser.driver.switchTo().defaultContent();
    }

Hope it helps you

0
votes

//It works with the below code.

const iframeLocator = browser.driver.findElement(by.css('iframe.selectedModulesIframe'));
        	browser.switchTo().frame(iframeLocator).then(function(){
        		
        		var EC4 = protractor.ExpectedConditions;
        		browser.wait(EC4.visibilityOf(element(by.linkText('192429'))),70000).then(function(){
        			console.log('Got the iframe Id');
        		})
        		browser.driver.findElement(protractor.By.linkText('192429')).click().then(function(){
            
            })