无法使用量角器针对非角度网页在iframe中定位元素

时间:2019-03-15 06:04:49

标签: protractor

在执行以下js时得到以下错误。请告知。

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>

这是我的代码:

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') 
        })

    })

也尝试以下代码:

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

})

错误响应:

[16:49:46] I /启动器-运行1个WebDriver实例 [16:49:46]我/已托管-使用http://localhost:4444/wd/hub上的硒服务器 已开始 得到了iframe iframe开关 [31mF [0m 失败: 1)受影响的乘客通知在时间表更改UI中验证APR   信息: [31m失败:没有这样的元素:无法找到元素:{“ method”:“ link text”,“ selector”:“ 192429”}       (会议信息:chrome = 72.0.3626.121)       (驱动程序信息:chromedriver = 2.46.628402(536cd7adbad73a3783fdc2cab92ab2ba7ec361e1),platform = Windows NT 10.0.15063 x86_64)[0m   堆:     NoSuchElementError:否这样的元素:无法找到元素:{“ method”:“链接文本”,“ selector”:“ 192429”}       (会议信息:chrome = 72.0.3626.121)       (驱动程序信息:chromedriver = 2.46.628402(536cd7adbad73a3783fdc2cab92ab2ba7ec361e1),platform = Windows NT 10.0.15063 x86_64)         在Object.checkLegacyResponse(C:\ Users \ sshaik \ eclipse-workspace \ Protractor_Orion \ protractor \ node_modules \ selenium-webdriver \ lib \ error.js:546:15)

HTML:

2 个答案:

答案 0 :(得分:0)

尝试以下一个

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

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

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

希望它对您有帮助

答案 1 :(得分:0)

//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(){
            
            })