gpt4 book ai didi

angularjs - 使用 Protractor 的 switchTo 定位非 Angular iframe 的元素

转载 作者:行者123 更新时间:2023-12-04 19:05:17 24 4
gpt4 key购买 nike

我有一个包含 iframe 的 angularjs 应用程序,该应用程序显示允许登录另一个网站的页面。我试图在 iframe 中包含的字段中放入一些值,但我无法使用任何定位器找到这些元素。

这是我的测试:

describe("Harvest", function() {

beforeEach(function () {

browser.get('http://localhost:8110/');

expect(browser.getCurrentUrl()).toMatch('_*#/login$');

element(by.model('user.username')).sendKeys('sam');
element(by.model('user.password')).sendKeys('pass');

element(by.id('bt_signin')).click();

});

afterEach(function () {
browser.executeScript('window.sessionStorage.clear();');
});

describe('A user', function () {

beforeEach(function () {
browser.get('http://localhost:8110/');
});

it('should be able to obtain an access token from harvest', function () {
expect(browser.getCurrentUrl()).toMatch('_*#/home$');

//Display and close the window
element(by.id('btHarvest')).click();

expect(element(by.id('modalHarvest')).isPresent()).toBe(true);

element(by.id('btCloseModal')).click();

expect(element(by.id('modalHarvest')).isPresent()).toBe(false);

//Authenticate into harvest
element(by.id('btHarvest')).click();

expect(element(by.id('modalHarvest')).isPresent()).toBe(true);

browser.switchTo().frame('iframeHarvest');

//It fails here with a null exceptions, guess it can't find it
element(by.id('email')).sendKeys(browser.params.harvestLogins.user);
element(by.id('user_password')).sendKeys(browser.params.harvestLogins.password);
element(by.id('sign-in-button')).click();

expect(element(by.name('commit')).isPresent()).toBe(true);

browser.driver.switchTo().defaultContent();



});

});

});

这是生成的异常
1) Harvest A user should be able to obtain an access token from harvest
Message:
[31mError: Error while waiting for Protractor to sync with the page: {}[0m
Stacktrace:
Error: Error while waiting for Protractor to sync with the page: {}
at Error (<anonymous>)
==== async task ====
WebDriver.executeScript()
at null.<anonymous> (/Users/samdurand/workspace/cake/subbie/src/test/web/js/features/harvest.js:45:22)
==== async task ====
Asynchronous test function: it()
Error
at null.<anonymous> (/Users/samdurand/workspace/cake/subbie/src/test/web/js/features/harvest.js:26:5)
at null.<anonymous> (/Users/samdurand/workspace/cake/subbie/src/test/web/js/features/harvest.js:20:3)
at Object.<anonymous> (/Users/samdurand/workspace/cake/subbie/src/test/web/js/features/harvest.js:1:63)

按照建议更正 iframe 调用后,我收到此错误:
1) Projects A user is possible to create a project based on harvest data
Message:
[31mError: Error while waiting for Protractor to sync with the page: {}[0m
Stacktrace:
Error: Error while waiting for Protractor to sync with the page: {}
at Error (<anonymous>)

最佳答案

如上所述,您面临的问题是因为 iframe您要切换到的是非 Angular 的。因此,element(by.id)切换到那个后将不起作用 iframe .相反,findElement需要使用!

关于angularjs - 使用 Protractor 的 switchTo 定位非 Angular iframe 的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26511193/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com