失败:元素不可交互:量角器/ Selenium Automation(ElementNotVisibleException)

时间:2019-07-16 15:45:20

标签: java angularjs typescript selenium protractor

我正在尝试自动化具有各种元素类型的页面。我可以使用量角器,TypeScript,jasmine2组合登录并导航到该页面

  • 当我尝试在字段中输入文本时,它会抛出

      

    消息:失败:元素不可交互。

  • 这是否意味着禁用整个ng-controller或ng-scope进行元素交互以实现自动化?

如果可以启用pageLoad页面上的元素,请告诉我一个解决方案?

    import { browser, by, element } from 'protractor';
    import { Locator } from 'protractor/built/locators';
    import { PageObjects } from '../TestPageObjects/OR';
    import { TestData } from '../TestData/TD';

    var po= new PageObjects();
    var data= new TestData();
    describe('Login', function() {
    it('Login to Server', function() {
    browser.get('http://server01/test/testapp.html');
    element(<Locator>by.xpath(po.login_username)).sendKeys(data.username);
    element(<Locator>by.xpath(po.login_password)).sendKeys(data.password);
    element(<Locator>by.xpath(po.login_loginBtn)).click();
    element(<Locator>by.xpath(po.MainMenu_setup)).click();
    element(<Locator>by.xpath(po.SETUP_company)).click();
    element(<Locator>by.xpath(po.COMPANY_companyDetails)).click();              
browser.switchTo().frame(element(by.id('ifmPortalInfrastturcture')).getWebElement());
    browser.sleep(10000);
   browser.element(<Locator>by.xpath(po.CompanyName)).clear();
              browser.element(<Locator>by.xpath(po.CompanyName)).sendKeys('ANN');   
 });
 });

我希望行为类似于输入文本,但是终端显示元素不可交互。

PageObject(PO)选择器如下:

export class PageObjects
{
    public login_username: string ='//*[@id="username"]';
    public login_password: string ='//*[@id="password"]';
    public login_loginBtn: string ='//*[@id="btnSubmit"]';
    public MainMenu_setup: string ='//a[span[text()="Setup"]]';
    public SETUP_company:  string ='//a[span[text()="Company"]]';
    public COMPANY_companyDetails:  string ='//a[span[text()="Company Details"]]'
    public CompanyName: string = '//label[contains(.,"Company Name")]/following::input[1]';
    //a[span[text()="Receipts"]]
    //a[span[text()="Control Text"]]
}

HTML页面在下面:

<html xmlns="http://www.w3.org/1999/xhtml" ng-app="portalInfrastructure" dir="ltr">
<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
    <title>iProof Axon</title>
    <link rel="icon" href="favicon.ico" type="image/ico" />
    <style>

@font-face {
    font-family: 'FontAwesome';
    src: url('iProofCDN/Templates/Default/Styles/LTR/assets/css/Common/icons/fontawesome/fonts/fontawesome-webfont.eot?v=4.7.0');
    src: url('iProofCDN/Templates/Default/Styles/LTR/assets/css/Common/icons/fontawesome/fonts/fontawesome-webfont.eot?#iefix&v=4.7.0') format('embedded-opentype'), 
         url('iProofCDN/Templates/Default/Styles/LTR/assets/css/Common/icons/fontawesome/fonts/fontawesome-webfont.woff2?v=4.7.0') format('woff2'), 
         url('iProofCDN/Templates/Default/Styles/LTR/assets/css/Common/icons/fontawesome/fonts/fontawesome-webfont.woff?v=4.7.0') format('woff'), 
         url('iProofCDN/Templates/Default/Styles/LTR/assets/css/Common/icons/fontawesome/fonts/fontawesome-webfont.ttf?v=4.7.0') format('truetype'), 
         url('iProofCDN/Templates/Default/Styles/LTR/assets/css/Common/icons/fontawesome/fonts/fontawesome-webfont.svg?v=4.7.0#fontawesomeregular') format('svg');
    font-weight: normal;
    font-style: normal
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}
    </style>
</head>

<body ng-controller="PortalInfrastructureController as menuList" class="pace-done " ng-init='setPageUrlByPageType("Authenticate", "#pageManager")' id="bdyPageManager">
    <div id="pageManager"></div>
    <div id="MultiWindowRight" class="noItem " style="display:none">
        <a href="#" class="ToggleRightMenu"><img data-imgsrc="/Templates/Default/Styles/LTR/assets/images/RightArrow.png" /></a>
        <div class="MultiWindow"></div>
    </div>    
    <script type="text/javascript" src="iProofCDN/Templates/Default/Scripts/JsBundle/Common/ProofConfig.js"></script>
</body>
</html>

<script type="text/javascript">
        window.top.ScriptLoader('PageManager', window.document, function () {
            //default
        });
</script>

1 个答案:

答案 0 :(得分:0)

经过研究,我的一位同事找到了解决方案。

容器元素被隐藏以供访问,我们使用以下脚本将其解锁:

JavascriptExecutor执行程序=(JavascriptExecutor)驱动程序; executor.executeScript(“ document.getElementById('Parks')。style.display ='block';”);

注意:名为“ Parks”的Div是xmlns中的一个子对象,它又是iFrame的子对象。