Finding all web elements using Ruby and Selenium -


i'm ruby , selenium webdriver noob...

instead of grabbing 1 element @ time , placing variable, i'd grab of web elements @ 1 time, includes buttons, fields, etc.

i've tried grabbing examples of find_elements off web it's not working, i'm doing wrong.

so need grab elements of web page , how use specific one?

thanks, scott

forgive ignorance of ruby having field decorators or way use pagefactory in java. there several great articles , blog posts using page object model , pagefactory. may not you're looking maybe ruby has similar.

the gist of pagefactory basically, creating class page , add webelement fields elements have id or name attribute. use same id/name value variable names. can use field decorators pass findby. call pagefactory.init(factory, object) in constructor , pagefactory find elements or list of elements.

let's see if can give qad example can idea , research using pom.

public abstract class pagebase implements wrapsdriver{      protected string url;     protected string title;     protected webdriver driver;     protected elementlocatorfactory factory;        public pagebase(webdriver driver, string pagetitle){         this.driver = driver;         this.title = pagetitle;         this.factory = new ajaxelementlocatorfactory(driver, 2);     }      abstract void open(); ...  }  public class somepage extends pagebase{ /* *<div id="thin_client_viewer" style="position: relative"> */     public webelement thin_client_viewer;      public webelement primarycontentlink; //<a id="primarycontentlink" style="display:none" href=""></a>     public webelement loadingspinner; //hidden <div id="loadingspinner" style="display: none;">     public webelement top_toolbar;      .     .     . 

you can declare lists , use custom decorators too:

   .     .     .      /*      * <div id="dijit_layout_layoutcontainer_0" class="dijitcontainer dijitlayoutcontainer       dijitalignclient" >      *       */     @findby(css="div[id^=\"dijit_layout_layoutcontainer_\"")     public list<webelement> dijit_layout_layoutcontainer_;     /*      * <span id="tabbednavigation_tab_0" class="tablabel" dojoattachpoint="containernode,focusnode" >      *        */      @findall(value = { @findby(classname="tablabel") })     public list<webelement> tableautabbednavigation_tab_;   ...  public somepage(webdriver driver){          super(driver, "page title");         url = driver.getcurrenturl();      } @override public void open(){      .     .     .     pagefactory.initelements(super.factory, this);     .     .     .   }      .     .     . 

}

the class instantiates or creates page calls open();

public class loginpage extends pagebase{         private webelement somepage_link;         .        .        .         public somepage clicklinktosomepage(){              .             .             .              driver.get(somepage_link.getattribute("href"));             somepage_link.click();             somepage page = new somepage(super.getwrappeddriver());             page.open();             return page;         }     .     .     .  } 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -