Hi Marcin
Thank you for your attention!
But unfortunately it doesn't work too:
return browser.withNewWindow({$('#newwindow').click()}, page: NewWindowPage) {
return txtElement
}
(I have just renamed divText to txtElement just for avoid naming collision
with method name)
Exception is:
simpleWindowModule.getDivText() == 'text'
| |
| groovy.lang.MissingPropertyException: Unable to resolve
txtElement as content for ModuledPage -> simpleWindowModule: SimpleModule,
or as a property on its Navigator context. Is txtElement a class you forgot
to import?
ModuledPage -> simpleWindowModule: SimpleModule
As you can see - geb doesn't search for txtElement in NewWindowPage.
But if I change this code and take txtElement from current page - it will
be okay (because NewWindowPage is really current page):
String getDivText() {
return browser.withNewWindow({$('#newwindow').click()}, page:
NewWindowPage) {
def page = browser.getPage()
return page.txtElement
}
}
четверг, 22 ноября 2018 г., 2:12:47 UTC+5 пользователь Marcin Erdmann
написал:
>
> Hi Yura,
>
> Yes, I'm afraid that you are indeed misusing Geb modules in this case.
>
> The issue you are seeing is because calls to $() from within a module
> resolve the passed selectors relative to the base of the module (
> http://gebish.org/manual/current/#base-and-context). In your case the
> base of the module is located within the original window and then you are
> trying to resolve a selector relative to it from within the new window. The
> web element which is backing your module base does not exist in the new
> window hence the error you are getting mentions an element has not been
> seen before (that element is the module base which is in the original
> window).
>
> The way to solve it is to model content of the newly opened window with a
> page class (see http://gebish.org/manual/current/#code-page-code-2) and
> use it from your module:
>
> class NewWindowPage extends Page {
> static content = {
> divText { $('div', id: 'divel').text() }
> }
> }
>
> class SimpleModule extends Module {
> String getDivText() {
> return browser.withNewWindow({$('#newwindow').click() }, page:
> NewWindowPage) {
> return divText
> }
> }
> }
>
--
You received this message because you are subscribed to the Google Groups "Geb
User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/geb-user/bd52bac3-5a29-4a1a-be9f-f880cdd50bbe%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.