Class: PageObject::Platforms::SeleniumWebDriver::PageObject

Inherits:
Object
  • Object
show all
Defined in:
lib/page-object/platforms/selenium_webdriver/page_object.rb

Overview

Selenium implementation of the page object platform driver. You should not use the class directly. Instead you should include the PageObject module in your page object and use the methods dynamically added from the PageObject::Accessors module.

Instance Method Summary collapse

Constructor Details

#initialize(browser) ⇒ PageObject

Returns a new instance of PageObject.



15
16
17
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 15

def initialize(browser)
  @browser = browser
end

Instance Method Details

#alert(frame = nil, &block) ⇒ Object

platform method to handle an alert popup See PageObject#alert



72
73
74
75
76
77
78
79
80
81
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 72

def alert(frame=nil, &block)
  yield
  begin
    alert = @browser.switch_to.alert
    value = alert.text
    alert.accept
  rescue Selenium::WebDriver::Error::NoAlertPresentError
  end
  value
end

#area_for(identifier) ⇒ Object

platform method to retrieve an area element



947
948
949
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 947

def area_for(identifier)
  find_selenium_element(identifier, Elements::Area, 'area')
end

#areas_for(identifier) ⇒ Object

platform method to return an array of area elements



954
955
956
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 954

def areas_for(identifier)
  find_selenium_elements(identifier, Elements::Area, 'area')
end

#attach_to_window(identifier, &block) ⇒ Object

platform method to handle attaching to a running window See PageObject#attach_to_window



122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 122

def attach_to_window(identifier, &block)
  value = identifier.values.first
  key = identifier.keys.first
  handles = @browser.window_handles
  handles.each do |handle|
    @browser.switch_to.window handle
    if (key == :title and value == @browser.title) or
      (key == :url and @browser.current_url.include?(value))
      return @browser.switch_to.window handle, &block
    end
  end
end

#audio_for(identifier) ⇒ Object

platform method to retrieve an audio element



975
976
977
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 975

def audio_for(identifier)
  find_selenium_element(identifier, Elements::Audio, 'audio')
end

#audios_for(identifier) ⇒ Object

platform method to return an array of audio elements



982
983
984
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 982

def audios_for(identifier)
  find_selenium_elements(identifier, Elements::Audio, 'audio')
end

#b_for(identifier) ⇒ Object

platform method to retrieve the h1 element See PageObject::Accessors#b



1061
1062
1063
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 1061

def b_for(identifier)
  find_selenium_element(identifier, Elements::Bold, 'b')
end

#b_text_for(identifier) ⇒ Object

platform method to retrieve the text from a b See PageObject::Accessors#b



1051
1052
1053
1054
1055
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 1051

def b_text_for(identifier)
  process_selenium_call(identifier, Elements::Bold, 'b') do |how, what|
    @browser.find_element(how, what).text
  end
end

#backObject

platform method to go back to the previous page See PageObject#back



177
178
179
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 177

def back
  @browser.navigate.back
end

#bs_for(identifier) ⇒ Object

platform method to retrieve all b elements



1068
1069
1070
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 1068

def bs_for(identifier)
  find_selenium_elements(identifier, Elements::Bold, 'b')
end

#button_for(identifier) ⇒ Object

platform method to retrieve a button element See PageObject::Accessors#button



517
518
519
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 517

def button_for(identifier)
  find_selenium_element(identifier, Elements::Button, 'input', :type => 'submit')
end

#buttons_for(identifier) ⇒ Object

platform method to retrieve an array of button elements



524
525
526
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 524

def buttons_for(identifier)
  find_selenium_elements(identifier, Elements::Button, 'input', :type => 'submit')
end

#canvas_for(identifier) ⇒ Object

platform method to retrieve a canvas element



961
962
963
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 961

def canvas_for(identifier)
  find_selenium_element(identifier, Elements::Canvas, 'canvas')
end

#canvass_for(identifier) ⇒ Object

platform method to return an array of canvas elements



968
969
970
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 968

def canvass_for(identifier)
  find_selenium_elements(identifier, Elements::Canvas, 'canvas')
end

#cell_for(identifier) ⇒ Object

platform method to retrieve a table cell element See PageObject::Accessors#cell



567
568
569
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 567

def cell_for(identifier)
  find_selenium_element(identifier, Elements::TableCell, 'td')
end

#cell_text_for(identifier) ⇒ Object

platform method to retrieve the text from a table cell See PageObject::Accessors#cell



557
558
559
560
561
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 557

def cell_text_for(identifier)
  process_selenium_call(identifier, Elements::TableCell, 'td') do |how, what|
    @browser.find_element(how, what).text
  end
end

#cells_for(identifier) ⇒ Object

platform method to retrieve all table cell elements



574
575
576
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 574

def cells_for(identifier)
  find_selenium_elements(identifier, Elements::TableCell, 'td')
end

#check_checkbox(identifier) ⇒ Object

platform method to check a checkbox See PageObject::Accessors#checkbox



377
378
379
380
381
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 377

def check_checkbox(identifier)
  process_selenium_call(identifier, Elements::CheckBox, 'input', :type => 'checkbox') do |how, what|
    @browser.find_element(how, what).click unless @browser.find_element(how, what).selected?
  end
end

#checkbox_checked?(identifier) ⇒ Boolean

platform method to determine if a checkbox is checked See PageObject::Accessors#checkbox

Returns:

  • (Boolean)


397
398
399
400
401
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 397

def checkbox_checked?(identifier)
  process_selenium_call(identifier, Elements::CheckBox, 'input', :type => 'checkbox') do |how, what|
    @browser.find_element(how, what).selected?
  end
end

#checkbox_for(identifier) ⇒ Object

platform method to return a PageObject::Elements::CheckBox element See PageObject::Accessors#checkbox



407
408
409
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 407

def checkbox_for(identifier)
  find_selenium_element(identifier, Elements::CheckBox, 'input', :type => 'checkbox')
end

#checkboxs_for(identifier) ⇒ Object

platform method to retrieve all checkbox elements



414
415
416
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 414

def checkboxs_for(identifier)
  find_selenium_elements(identifier, Elements::CheckBox, 'input', :type => 'checkbox')
end

#clear_cookiesObject

platform method to clear the cookies from the browser See PageObject#clear_cookies



193
194
195
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 193

def clear_cookies
  @browser.manage.delete_all_cookies
end

#click_area_for(identifier) ⇒ Object

platform method to click on an area



938
939
940
941
942
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 938

def click_area_for(identifier)
  process_selenium_call(identifier, Elements::Area, 'area') do |how, what|
    @browser.find_element(how, what).click
  end
end

#click_button_for(identifier) ⇒ Object

platform method to click a button See PageObject::Accessors#button



507
508
509
510
511
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 507

def click_button_for(identifier)
  process_selenium_call(identifier, Elements::Button, 'input', :type => 'submit') do |how, what|
    @browser.find_element(how, what).click
  end
end

platform method to click a link See PageObject::Accessors#link



352
353
354
355
356
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 352

def click_link_for(identifier)
  process_selenium_call(identifier, Elements::Link, 'a') do |how, what|
    @browser.find_element(how, what).click
  end
end

#confirm(response, frame = nil, &block) ⇒ Object

platform method to handle a confirm popup See PageObject#confirm



87
88
89
90
91
92
93
94
95
96
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 87

def confirm(response, frame=nil, &block)
  yield
  begin
    alert = @browser.switch_to.alert
    value = alert.text
    response ? alert.accept : alert.dismiss
  rescue Selenium::WebDriver::Error::NoAlertPresentError
  end
  value
end

#current_urlObject

platform method to get the current url See PageObject#current_url



31
32
33
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 31

def current_url
  @browser.current_url
end

#div_for(identifier) ⇒ Object

platform method to return a PageObject::Elements::Div element See PageObject::Accessors#div



467
468
469
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 467

def div_for(identifier)
  find_selenium_element(identifier, Elements::Div, 'div')
end

#div_text_for(identifier) ⇒ Object

platform method to return the text for a div See PageObject::Accessors#div



457
458
459
460
461
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 457

def div_text_for(identifier)
  process_selenium_call(identifier, Elements::Div, 'div') do |how, what|
    @browser.find_element(how, what).text
  end
end

#divs_for(identifier) ⇒ Object

platform method to retrieve all div elements



474
475
476
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 474

def divs_for(identifier)
  find_selenium_elements(identifier, Elements::Div, 'div')
end

#element_for(tag, identifier) ⇒ Object

platform method to retrieve a generic element See PageObject::Accessors#element



1004
1005
1006
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 1004

def element_for(tag, identifier)
  find_selenium_element(identifier, Elements::Element, tag.to_s)
end

#element_with_focusObject

find the element that has focus



138
139
140
141
142
143
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 138

def element_with_focus
  element = @browser.execute_script("return document.activeElement")
  type = element.attribute(:type).to_s.downcase if element.tag_name.to_sym == :input
  cls = ::PageObject::Elements.element_class_for(element.tag_name, type)
  cls.new(element, :platform => :selenium_webdriver)
end

#elements_for(tag, identifier) ⇒ Object

platform method to retrieve a collection of generic elements See PageObject::Accessors#elements



1012
1013
1014
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 1012

def elements_for(tag, identifier)
  find_selenium_elements(identifier, Elements::Element, tag.to_s)
end

#execute_script(script, *args) ⇒ Object

platform method to execute javascript on the browser See PageObject#execute_script



114
115
116
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 114

def execute_script(script, *args)
  @browser.execute_script(script, *args)
end

#file_field_for(identifier) ⇒ Object

platform method to retrieve a file_field element See PageObject::Accessors#file_field



924
925
926
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 924

def file_field_for(identifier)
  find_selenium_element(identifier, Elements::FileField, 'input', :type => 'file')
end

#file_field_value_set(identifier, value) ⇒ Object

platform method to set the file on a file_field element See PageObject::Accessors#file_field



914
915
916
917
918
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 914

def file_field_value_set(identifier, value)
  process_selenium_call(identifier, Elements::FileField, 'input', :type => 'file') do |how, what|
    @browser.find_element(how, what).send_keys(value)
  end
end

#file_fields_for(identifier) ⇒ Object

platform method to return an array of file field elements



931
932
933
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 931

def file_fields_for(identifier)
  find_selenium_elements(identifier, Elements::FileField, 'input', :type => 'file')
end

#form_for(identifier) ⇒ Object

platform method to retrieve a form element See PageObject::Accessors#form



622
623
624
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 622

def form_for(identifier)
  find_selenium_element(identifier, Elements::Form, 'form')
end

#forms_for(identifier) ⇒ Object

platform method to retrieve all forms



629
630
631
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 629

def forms_for(identifier)
  find_selenium_elements(identifier, Elements::Form, 'form')
end

#forwardObject

platform method to go forward to the next page See PageObject#forward



185
186
187
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 185

def forward
  @browser.navigate.forward
end

#h1_for(identifier) ⇒ Object

platform method to retrieve the h1 element See PageObject::Accessors#h1



722
723
724
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 722

def h1_for(identifier)
  find_selenium_element(identifier, Elements::Heading, 'h1')
end

#h1_text_for(identifier) ⇒ Object

platform method to retrieve the text from a h1 See PageObject::Accessors#h1



712
713
714
715
716
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 712

def h1_text_for(identifier)
  process_selenium_call(identifier, Elements::Heading, 'h1') do |how, what|
    @browser.find_element(how, what).text
  end
end

#h1s_for(identifier) ⇒ Object

platform method to retrieve all h1 elements



729
730
731
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 729

def h1s_for(identifier)
  find_selenium_elements(identifier, Elements::Heading, 'h1')
end

#h2_for(identifier) ⇒ Object

platform method to retrieve the h2 element See PageObject::Accessors#h2



747
748
749
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 747

def h2_for(identifier)
  find_selenium_element(identifier, Elements::Heading, 'h2')
end

#h2_text_for(identifier) ⇒ Object

platform method to retrieve the text from a h2 See PageObject::Accessors#h2



737
738
739
740
741
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 737

def h2_text_for(identifier)
  process_selenium_call(identifier, Elements::Heading, 'h2') do |how, what|
    @browser.find_element(how, what).text
  end
end

#h2s_for(identifier) ⇒ Object

platform method to retrieve all h2 elements



754
755
756
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 754

def h2s_for(identifier)
  find_selenium_elements(identifier, Elements::Heading, 'h2')
end

#h3_for(identifier) ⇒ Object

platform method to retrieve the h3 element See PageObject::Accessors#h3



772
773
774
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 772

def h3_for(identifier)
  find_selenium_element(identifier, Elements::Heading, 'h3')
end

#h3_text_for(identifier) ⇒ Object

platform method to retrieve the text from a h3 See PageObject::Accessors#h3



762
763
764
765
766
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 762

def h3_text_for(identifier)
  process_selenium_call(identifier, Elements::Heading, 'h3') do |how, what|
    @browser.find_element(how, what).text
  end
end

#h3s_for(identifier) ⇒ Object

platform method to retrieve all h3 elements



779
780
781
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 779

def h3s_for(identifier)
  find_selenium_elements(identifier, Elements::Heading, 'h3')
end

#h4_for(identifier) ⇒ Object

platform method to retrieve the h4 element See PageObject::Accessors#h4



797
798
799
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 797

def h4_for(identifier)
  find_selenium_element(identifier, Elements::Heading, 'h4')
end

#h4_text_for(identifier) ⇒ Object

platform method to retrieve the text from a h4 See PageObject::Accessors#h4



787
788
789
790
791
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 787

def h4_text_for(identifier)
  process_selenium_call(identifier, Elements::Heading, 'h4') do |how, what|
    @browser.find_element(how, what).text
  end
end

#h4s_for(identifier) ⇒ Object

platform method to retrieve all h4 elements



804
805
806
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 804

def h4s_for(identifier)
  find_selenium_elements(identifier, Elements::Heading, 'h4')
end

#h5_for(identifier) ⇒ Object

platform method to retrieve the h5 element See PageObject::Accessors#h5



822
823
824
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 822

def h5_for(identifier)
  find_selenium_element(identifier, Elements::Heading, 'h5')
end

#h5_text_for(identifier) ⇒ Object

platform method to retrieve the text from a h5 See PageObject::Accessors#h5



812
813
814
815
816
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 812

def h5_text_for(identifier)
  process_selenium_call(identifier, Elements::Heading, 'h5') do |how, what|
    @browser.find_element(how, what).text
  end
end

#h5s_for(identifier) ⇒ Object

platform method to retrieve all h5 elements



829
830
831
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 829

def h5s_for(identifier)
  find_selenium_elements(identifier, Elements::Heading, 'h5')
end

#h6_for(identifier) ⇒ Object

platform method to retrieve the h6 element See PageObject::Accessors#h6



847
848
849
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 847

def h6_for(identifier)
  find_selenium_element(identifier, Elements::Heading, 'h6')
end

#h6_text_for(identifier) ⇒ Object

platform method to retrieve the text from a h6 See PageObject::Accessors#h6



837
838
839
840
841
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 837

def h6_text_for(identifier)
  process_selenium_call(identifier, Elements::Heading, 'h6') do |how, what|
    @browser.find_element(how, what).text
  end
end

#h6s_for(identifier) ⇒ Object

platform method to retrieve all h6 elements



854
855
856
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 854

def h6s_for(identifier)
  find_selenium_elements(identifier, Elements::Heading, 'h6')
end

#hidden_field_for(identifier) ⇒ Object

platform method to retrieve a hidden field element See PageObject::Accessors#hidden_field



256
257
258
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 256

def hidden_field_for(identifier)
  find_selenium_element(identifier, Elements::HiddenField, 'input', :type => 'hidden')
end

#hidden_field_value_for(identifier) ⇒ Object

platform method to get the value stored in a hidden field See PageObject::Accessors#hidden_field



246
247
248
249
250
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 246

def hidden_field_value_for(identifier)
  process_selenium_call(identifier, Elements::HiddenField, 'input', :type => 'hidden') do |how, what|
    @browser.find_element(how, what).attribute('value')
  end
end

#hidden_fields_for(identifier) ⇒ Object

platform method to retrieve all hidden field elements



263
264
265
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 263

def hidden_fields_for(identifier)
  find_selenium_elements(identifier, Elements::HiddenField, 'input', :type => 'hidden')
end

#htmlObject

platform method to retrieve the html for the current page See PageObject#html



47
48
49
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 47

def html
  @browser.page_source
end

#image_for(identifier) ⇒ Object

platform method to retrieve an image element See PageObject::Accessors#image



607
608
609
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 607

def image_for(identifier)
  find_selenium_element(identifier, Elements::Image, 'img')
end

#images_for(identifier) ⇒ Object

platform method to retrieve all image elements



614
615
616
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 614

def images_for(identifier)
  find_selenium_elements(identifier, Elements::Image, 'img')
end

#in_frame(identifier, frame = nil, &block) ⇒ Object

platform method to switch to a frame and execute a block See PageObject#in_frame



149
150
151
152
153
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 149

def in_frame(identifier, frame=nil, &block)
  switch_to_frame([frame: identifier])
  block.call(nil)
  @browser.switch_to.default_content
end

#in_iframe(identifier, frame = nil, &block) ⇒ Object

platform method to switch to an iframe and execute a block See PageObject#in_frame



159
160
161
162
163
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 159

def in_iframe(identifier, frame=nil, &block)
  switch_to_frame([iframe: identifier])
  block.call(nil)
  @browser.switch_to.default_content
end

#label_for(identifier) ⇒ Object

platform method to return a PageObject::Elements::Label element See PageObject::Accessors#label



898
899
900
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 898

def label_for(identifier)
  find_selenium_element(identifier, Elements::Label, 'label')
end

#label_text_for(identifier) ⇒ Object

platform method to return the text for a label See PageObject::Accessors#label



887
888
889
890
891
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 887

def label_text_for(identifier)
  process_selenium_call(identifier, Elements::Label, 'label') do |how, what|
    @browser.find_element(how, what).text
  end
end

#labels_for(identifier) ⇒ Object

platform method to retrieve all label elements



906
907
908
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 906

def labels_for(identifier)
  find_selenium_elements(identifier, Elements::Label, 'label')
end

platform method to return a PageObject::Elements::Link object see PageObject::Accessors#link



362
363
364
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 362

def link_for(identifier)
  find_selenium_element(identifier, Elements::Link, 'a')
end

platform method to retrieve all link elements



369
370
371
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 369

def links_for(identifier)
  find_selenium_elements(identifier, Elements::Link, 'a')
end

#list_item_for(identifier) ⇒ Object

platform method to retrieve a list item element See PageObject::Accessors#list_item



647
648
649
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 647

def list_item_for(identifier)
  find_selenium_element(identifier, Elements::ListItem, 'li')
end

#list_item_text_for(identifier) ⇒ Object

platform method to retrieve the text from a list item See PageObject::Accessors#list_item



637
638
639
640
641
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 637

def list_item_text_for(identifier)
  process_selenium_call(identifier, Elements::ListItem, 'li') do |how, what|
    @browser.find_element(how, what).text
  end
end

#list_items_for(identifier) ⇒ Object

platform method to retrieve all list items



654
655
656
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 654

def list_items_for(identifier)
  find_selenium_elements(identifier, Elements::ListItem, 'li')
end

platform method to navigate to a provided url See PageObject#navigate_to



23
24
25
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 23

def navigate_to(url)
  @browser.navigate.to url
end

#ordered_list_for(identifier) ⇒ Object

platform method to retrieve an ordered list element See PageObject::Accessors#ordered_list



697
698
699
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 697

def ordered_list_for(identifier)
  find_selenium_element(identifier, Elements::OrderedList, 'ol')
end

#ordered_list_text_for(identifier) ⇒ Object

platform method to retrieve the text from an ordered list See PageObject::Accessors#ordered_list



687
688
689
690
691
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 687

def ordered_list_text_for(identifier)
  process_selenium_call(identifier, Elements::OrderedList, 'ol') do |how, what|
    @browser.find_element(how, what).text
  end
end

#ordered_lists_for(identifier) ⇒ Object

platform method to retrieve all ordered lists



704
705
706
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 704

def ordered_lists_for(identifier)
  find_selenium_elements(identifier, Elements::OrderedList, 'ol')
end

#page_for(identifier, page_class) ⇒ Object

platform method to return a PageObject rooted at an element See PageObject::Accessors#page_section



1020
1021
1022
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 1020

def page_for(identifier, page_class)
  find_selenium_page(identifier, page_class)
end

#pages_for(identifier, page_class) ⇒ Object

platform method to return a collection of PageObjects rooted at elements See PageObject::Accessors#page_sections



1028
1029
1030
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 1028

def pages_for(identifier, page_class)
  SectionCollection.new(find_selenium_pages(identifier, page_class))
end

#paragraph_for(identifier) ⇒ Object

platform method to retrieve the paragraph element See PageObject::Accessors#paragraph



872
873
874
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 872

def paragraph_for(identifier)
  find_selenium_element(identifier, Elements::Paragraph, 'p')
end

#paragraph_text_for(identifier) ⇒ Object

platform method to retrieve the text for a paragraph See PageObject::Accessors#paragraph



862
863
864
865
866
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 862

def paragraph_text_for(identifier)
  process_selenium_call(identifier, Elements::Paragraph, 'p') do |how, what|
    @browser.find_element(how, what).text
  end
end

#paragraphs_for(identifier) ⇒ Object

platform method to retrieve all paragraph elements



879
880
881
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 879

def paragraphs_for(identifier)
  find_selenium_elements(identifier, Elements::Paragraph, 'p')
end

#prompt(answer, frame = nil, &block) ⇒ Object

platform method to handle a prompt popup See PageObject#prompt



102
103
104
105
106
107
108
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 102

def prompt(answer, frame=nil, &block)
  @browser.execute_script "window.prompt = function(text, value) { window.__lastWatirPrompt = { message: text, default_value: value }; return #{answer}; }"
  yield
  result = @browser.execute_script "return window.__lastWatirPrompt"
  result && result.dup.each_key { |k| result[k.to_sym] = result.delete(k) }
  result
end

#radio_button_for(identifier) ⇒ Object

platform method to return a PageObject::Eements::RadioButton element See PageObject::Accessors#radio_button



442
443
444
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 442

def radio_button_for(identifier)
  find_selenium_element(identifier, Elements::RadioButton, 'input', :type => 'radio')
end

#radio_buttons_for(identifier) ⇒ Object

platform method to retrieve all radio button elements



449
450
451
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 449

def radio_buttons_for(identifier)
  find_selenium_elements(identifier, Elements::RadioButton, 'input', :type => 'radio')
end

#radio_selected?(identifier) ⇒ Boolean

platform method to determine if a radio button is selected See PageObject::Accessors#radio_button

Returns:

  • (Boolean)


432
433
434
435
436
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 432

def radio_selected?(identifier)
  process_selenium_call(identifier, Elements::RadioButton, 'input', :type => 'radio') do |how, what|
    @browser.find_element(how, what).selected?
  end
end

#refreshObject

platform method to refresh the page See PageObject#refresh



169
170
171
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 169

def refresh
  @browser.navigate.refresh
end

#row_for(identifier) ⇒ Object

platform method to retrieve a table row element See PageObject::Accessors#row



592
593
594
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 592

def row_for(identifier)
  find_selenium_element(identifier, Elements::TableRow, 'tr')
end

#row_text_for(identifier) ⇒ Object

platform method to retrieve the text from a table row See PageObject::Accessors#row



582
583
584
585
586
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 582

def row_text_for(identifier)
  process_selenium_call(identifier, Elements::TableRow, 'tr') do |how, what|
    @browser.find_element(how, what).text
  end
end

#rows_for(identifier) ⇒ Object

platform method to retrieve all table row elements



599
600
601
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 599

def rows_for(identifier)
  find_selenium_elements(identifier, Elements::TableRow, 'tr')
end

#save_screenshot(file_name) ⇒ Object

platform method to save the current screenshot to a file See PageObject#save_screenshot



201
202
203
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 201

def save_screenshot(file_name)
  @browser.save_screenshot(file_name)
end

#select_list_for(identifier) ⇒ Object

platform method to return the select list element See PageObject::Accessors#select_list



337
338
339
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 337

def select_list_for(identifier)
  find_selenium_element(identifier, Elements::SelectList, 'select')
end

#select_list_value_for(identifier) ⇒ Object

platform method to get the currently selected value from a select list See PageObject::Accessors#select_list



308
309
310
311
312
313
314
315
316
317
318
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 308

def select_list_value_for(identifier)
  process_selenium_call(identifier, Elements::SelectList, 'select') do |how, what|
    selected = nil
    @browser.find_element(how, what).find_elements(:tag_name => 'option').each do |o|
      if selected.nil?
        selected = o.text if o.selected?
      end
    end
    selected
  end
end

#select_list_value_set(identifier, value) ⇒ Object

platform method to select a value from a select list See PageObject::Accessors#select_list



324
325
326
327
328
329
330
331
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 324

def select_list_value_set(identifier, value)
  process_selenium_call(identifier, Elements::SelectList, 'select') do |how, what|
    select_list = @browser.find_element(how, what)
    select_list.find_elements(:tag_name => 'option').find do |option|
      option.text == value
    end.click
  end
end

#select_lists_for(identifier) ⇒ Object

platform method to retrieve all select list elements



344
345
346
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 344

def select_lists_for(identifier)
  find_selenium_elements(identifier, Elements::SelectList, 'select')
end

#select_radio(identifier) ⇒ Object

platform method to select a radio button See PageObject::Accessors#radio_button



422
423
424
425
426
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 422

def select_radio(identifier)
  process_selenium_call(identifier, Elements::RadioButton, 'input', :type => 'radio') do |how, what|
    @browser.find_element(how, what).click unless @browser.find_element(how, what).selected?
  end
end

#span_for(identifier) ⇒ Object

platform method to return a PageObject::Elements::Span element See PageObject::Accessors#span



492
493
494
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 492

def span_for(identifier)
  find_selenium_element(identifier, Elements::Span, 'span')
end

#span_text_for(identifier) ⇒ Object

platform method to return the text for a span See PageObject::Accessors#span



482
483
484
485
486
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 482

def span_text_for(identifier)
  process_selenium_call(identifier, Elements::Span, 'span') do |how, what|
    @browser.find_element(how, what).text
  end
end

#spans_for(identifier) ⇒ Object

platform method to retrieve all span elements



499
500
501
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 499

def spans_for(identifier)
  find_selenium_elements(identifier, Elements::Span, 'span')
end

#svg_for(identifier) ⇒ Object

platform method to return a svg element



1035
1036
1037
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 1035

def svg_for(identifier)
  find_selenium_element(identifier, Elements::Element, 'svg')
end

#svgs_for(identifier) ⇒ Object

platform method to return an array of svg elements



1042
1043
1044
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 1042

def svgs_for(identifier)
  find_selenium_elements(identifier, Elements::Element, 'svg')
end

#table_for(identifier) ⇒ Object

platform method to retrieve a table element See PageObject::Accessors#table



542
543
544
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 542

def table_for(identifier)
  find_selenium_element(identifier, Elements::Table, 'table')
end

#table_text_for(identifier) ⇒ Object

platform method to return the text for a table See PageObject::Accessors#table



532
533
534
535
536
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 532

def table_text_for(identifier)
  process_selenium_call(identifier, Elements::Table, 'table') do |how, what|
    @browser.find_element(how, what).text
  end
end

#tables_for(identifier) ⇒ Object

platform method to retrieve all table elements



549
550
551
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 549

def tables_for(identifier)
  find_selenium_elements(identifier, Elements::Table, 'table')
end

#textObject

platform method to retrieve the text from the current page See PageObject#text



39
40
41
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 39

def text
  @browser.find_element(:tag_name, 'body').text
end

#text_area_for(identifier) ⇒ Object

platform method to get the text area element See PageObject::Accessors#text_area



293
294
295
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 293

def text_area_for(identifier)
  find_selenium_element(identifier, Elements::TextArea, 'textarea')
end

#text_area_value_for(identifier) ⇒ Object

platform method to get the text from a textarea See PageObject::Accessors#text_area



283
284
285
286
287
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 283

def text_area_value_for(identifier)
  process_selenium_call(identifier, Elements::TextArea, 'textarea') do |how, what|
    @browser.find_element(how, what).attribute('value')
  end
end

#text_area_value_set(identifier, value) ⇒ Object

platform method to set text in a textarea See PageObject::Accessors#text_area



271
272
273
274
275
276
277
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 271

def text_area_value_set(identifier, value)
  process_selenium_call(identifier, Elements::TextArea, 'textarea') do |how, what|
    text_area = @browser.find_element(how, what)
    text_area.clear
    text_area.send_keys(value)
  end
end

#text_areas_for(identifier) ⇒ Object

platform method to retrieve all text area elements



300
301
302
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 300

def text_areas_for(identifier)
  find_selenium_elements(identifier, Elements::TextArea, 'textarea')
end

#text_field_for(identifier) ⇒ Object

platform method to retrieve a text field element See PageObject::Accessors#text_field



231
232
233
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 231

def text_field_for(identifier)
  find_selenium_element(identifier, Elements::TextField, 'input', :type => 'text')
end

#text_field_value_for(identifier) ⇒ Object

platform method to get the value stored in a text field See PageObject::Accessors#text_field



209
210
211
212
213
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 209

def text_field_value_for(identifier)
  process_selenium_call(identifier, Elements::TextField, 'input', :type => 'text') do |how, what|
    @browser.find_element(how, what).attribute('value')
  end
end

#text_field_value_set(identifier, value) ⇒ Object

platform method to set the value for a text field See PageObject::Accessors#text_field



220
221
222
223
224
225
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 220

def text_field_value_set(identifier, value)
  process_selenium_call(identifier, Elements::TextField, 'input', :type => 'text') do |how, what|
    @browser.find_element(how, what).clear
    @browser.find_element(how, what).send_keys(value)
  end
end

#text_fields_for(identifier) ⇒ Object

platform method to retrieve all text field elements



238
239
240
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 238

def text_fields_for(identifier)
  find_selenium_elements(identifier, Elements::TextField, 'input', :type => 'text')
end

#titleObject

platform method to retrieve the title for the current page See PageObject#title



55
56
57
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 55

def title
  @browser.title
end

#uncheck_checkbox(identifier) ⇒ Object

platform method to uncheck a checkbox See PageObject::Accessors#checkbox



387
388
389
390
391
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 387

def uncheck_checkbox(identifier)
  process_selenium_call(identifier, Elements::CheckBox, 'input', :type => 'checkbox') do |how, what|
    @browser.find_element(how, what).click if @browser.find_element(how, what).selected?
  end
end

#unordered_list_for(identifier) ⇒ Object

platform method to retrieve an unordered list element See PageObject::Accessors#unordered_list



672
673
674
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 672

def unordered_list_for(identifier)
  find_selenium_element(identifier, Elements::UnorderedList, 'ul')
end

#unordered_list_text_for(identifier) ⇒ Object

platform method to retrieve the text from an unordered list See PageObject::Accessors#unordered_list



662
663
664
665
666
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 662

def unordered_list_text_for(identifier)
  process_selenium_call(identifier, Elements::UnorderedList, 'ul') do |how, what|
    @browser.find_element(how, what).text
  end
end

#unordered_lists_for(identifier) ⇒ Object

platform method to retrieve all unordered lists



679
680
681
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 679

def unordered_lists_for(identifier)
  find_selenium_elements(identifier, Elements::UnorderedList, 'ul')
end

#video_for(identifier) ⇒ Object

platform method to retrieve a video element



989
990
991
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 989

def video_for(identifier)
  find_selenium_element(identifier, Elements::Video, 'video')
end

#videos_for(identifier) ⇒ Object

platform method to return an array of video elements



996
997
998
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 996

def videos_for(identifier)
  find_selenium_elements(identifier, Elements::Video, 'video')
end

#wait_until(timeout, message = nil, &block) ⇒ Object

platform method to wait for a block to return true See PageObject#wait_until



63
64
65
66
# File 'lib/page-object/platforms/selenium_webdriver/page_object.rb', line 63

def wait_until(timeout, message = nil, &block)
  wait = ::Selenium::WebDriver::Wait.new({:timeout => timeout, :message => message})
  wait.until &block
end