2017-08-23 34 views
2

我有一個頁面,它由框架組成。我想訪問框架的元素並操作它們。我想用模塊來實現我的更改。這是我的代碼的樣子。無法使用geb groovy訪問模塊元素

<html> 
<body> 
    <frame name="header" ></frame> 
    <frame name="center" > 


     <input name='quantity' type='text'> 
     <input name='ok' type='radio' value='ok'> 
    </frame> 
    <frame name="footer" ></frame> 

然後,我有這樣的

class myMainPage extends Page { 
    static content = { 
     myModule{module FrameModule} 
    } 
} 


class FrameModule extends Module { 
    def FrameElement 
    static content = { 
    Myframe { $('frame', name:'center') } 
    FrameElement {Myframe.find('input[name="quantity"]')} 
    myQuantity = FrameElement.module(TextInput) 
    myQuantity.text = '10' 
    } 

} 

我與模塊的安裝測試,這是這樣

Then: 

    to myMainPage 
and: 
    myModule.myQuantity 

Groovy的頁面類,我得到

類沒有這樣的屬性的TextInput:FrameModule

如何處理這些幀的元素

+0

請看http://gebish.org/manual/current/#dealing-with-frames你的FrameModule代碼看起來很奇怪,你可以確保這是你正在使用的確切代碼。 –

回答

0

看起來你需要導入

import geb.module.TextInput 

,除非你沒有做到這一點,只是沒有包含在你的文章中。

其實,仔細看,你應該消除你的FrameElement,而是像下面那樣聲明myQuantity。這將消除一些絨毛並將其簡化爲一行,以找到該元素並將其實例化爲TextInput模塊。

myQuantity = {$("input", name: "quantity").module(TextInput)} 

比你應該能夠像你目前正在做myModule.myQuantity。