3

I have a text field that I am trying to manipulate with Watir Webdriver in Ruby, which is in this format:

<div class="fieldwrapper" ng-hide="tempPageContent.eulaModal.standardEula">
    <label class="ng-binding">Custom License Agreement</label>

    <textarea ng-model="tempEula.EULAText" class="med ng-pristine ng-valid"></textarea>
    <!-- <span text-area-with-counter="tempEula.EULAText" 
        text-limit="{{ referenceData.appMetaDataReference.maxEulaChars }}" 
        text-area-class="med"
        text-area-required="tempPageContent.eulaModal.customEula"
        text-area-itc-field-server-error="versionInfo.eula.errorKeys"
        text-area-itc-field-orig-val="orignalVersionInfo.eula.EULAText" 
        text-area-itc-field-cur-val="tempEula.EULAText"
        text-area-itc-empty-errormsg="Enter the license agreement"
        text-area-itc-char-exceed-errormsg="The license agreement can not exceed {{ referenceData.appMetaDataReference.maxEulaChars }} characters"></span> -->
</div>

I need to insert a large String that is extracted from a text file into this text field, but using the standard Watir.textarea.set won't work as it would time-out in 30 seconds. Here is what I am trying to do at the moment:

@browser.execute_script("arguments[0].value = arguments[1]", text_field, eula_text)

which injects the text into the text field, but does not enable the 'Save' button, which is triggered by the native set method, but not by Javascript.

I saw some post by jarib, who proposed the usage of Mac's pbcopy for copying text and then using the send_keys([:command, 'v']), but using the send_keys does not work, although the text is in the IO buffer. I tried both open and popen methods. I also tried using pbpaste on Watir textarea element...

I cannot think of a novel idea to accomplish my task and any pointers in the right direction would be appreciated. I am just not familiar with the way AngularJS text fields work with text input. I am using the latest watir-webdriver 0.9.1 and chromedriver.

Community
  • 1
  • 1
marat75
  • 52
  • 7

1 Answers1

4

3 possibilities:

1) Increase the client timeout:

client = Selenium::WebDriver::Remote::Http::Default.new
client.timeout = 180

b = Watir::Browser.new :chrome, http_client: client

2) Don't do all the text at once:

File.open('xxx.txt').each do |line|
  textfield.append(line)
end

3) Use your javascript code to copy everything in, then use textfield.append(' ') to enable the save button.

titusfortner
  • 4,099
  • 2
  • 15
  • 29