将大文本粘贴到Ruby中的Watir Webdriver文本字段中

时间:2016-04-16 02:36:43

标签: ruby watir watir-webdriver selenium-chromedriver

我有一个文本字段,我试图用Ruby中的Watir Webdriver进行操作,格式为:

<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>

我需要将从文本文件中提取的大型String插入到此文本字段中,但使用标准Watir.textarea.set不会在30秒内超时。这就是我现在要做的事情:

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

将文本注入文本字段,但不启用&#39;保存&#39;按钮,由本机set方法触发,但不是由Javascript触发。

我在jarib看了一些帖子,他建议使用Mac的pbcopy复制文本,然后使用send_keys([:command,&#39; v&#39;]),但是使用send_keys不起作用,尽管文本在IO缓冲区中。我尝试了open和popen方法。我也尝试在Watir textarea元素上使用pbpaste ......

我无法想到一个新颖的想法来完成我的任务,任何指向正确方向的人都会受到赞赏。我只是不熟悉AngularJS文本字段与文本输入一起使用的方式。 我正在使用最新的watir-webdriver 0.9.1和chromedriver。

1 个答案:

答案 0 :(得分:4)

3种可能性:

1)增加客户端超时:

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

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

2)不要一次完成所有文本:

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

3)使用您的javascript代码复制所有内容,然后使用textfield.append(' ')启用保存按钮。