Module: OnlyofficeWebdriverWrapper::GetTextMethods
- Included in:
- WebDriver
- Defined in:
- lib/onlyoffice_webdriver_wrapper/webdriver/get_text_methods.rb
Overview
Method to get text
Instance Method Summary collapse
-
#get_text(xpath_name, wait_until_visible = true) ⇒ String
Get text of current element.
-
#get_text_array(array_elements) ⇒ Array<String>
Get text from all elements with specified xpath.
-
#get_text_by_js(xpath) ⇒ String
Get text in object by xpath.
-
#get_text_of_several_elements(xpath_several_elements) ⇒ Array<String>
Get text from several elements This method filter out all elements with empty text.
Instance Method Details
#get_text(xpath_name, wait_until_visible = true) ⇒ String
Get text of current element
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/get_text_methods.rb', line 10 def get_text(xpath_name, wait_until_visible = true) wait_until_element_visible(xpath_name) if wait_until_visible element = get_element(xpath_name) webdriver_error("get_text(#{xpath_name}, #{wait_until_visible}) not found element by xpath") if element.nil? if element.tag_name == 'input' || element.tag_name == 'textarea' element.attribute('value') else element.text end end |
#get_text_array(array_elements) ⇒ Array<String>
Get text from all elements with specified xpath
34 35 36 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/get_text_methods.rb', line 34 def get_text_array(array_elements) get_elements(array_elements).map { |current_element| get_text(current_element) } end |
#get_text_by_js(xpath) ⇒ String
Get text in object by xpath
25 26 27 28 29 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/get_text_methods.rb', line 25 def get_text_by_js(xpath) text = execute_javascript("return #{dom_element_by_xpath(xpath)}.textContent") text = execute_javascript("return #{dom_element_by_xpath(xpath)}.value") if text.empty? text end |
#get_text_of_several_elements(xpath_several_elements) ⇒ Array<String>
Get text from several elements This method filter out all elements with empty text
42 43 44 45 46 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/get_text_methods.rb', line 42 def get_text_of_several_elements(xpath_several_elements) @driver.find_elements(:xpath, xpath_several_elements).filter_map do |element| element.text unless element.text == '' end end |