driver.SendKeys()方法自动提交页面

时间:2016-03-29 12:17:29

标签: javascript java html selenium

我真的遇到了一个问题,我想在文本区域中设置文本。我已尝试所有列出的交替方式

String line1="1.    "+rca+"\n";

    String line2="2.    Fixes implemented to resolve the issue :";//\n"+fixes+"\n";

其中rca和fixes也可以是多行字符串,具体取决于先前评论的值

      //works fine for single line fails in nultiple line 
   ((JavascriptExecutor)driver).executeScript("document.getElementById('comment').value='"+line2"';");
//Automatically clicks on submit button i guess that is not required
    driver.findElement(By.id("comment")).sendKeys(line3+line4);

我使用sendKeys方法执行自动点击提交按钮,我猜想写在原始页面的文本区域下面。

我使用了javascript执行程序,但它仍然无法解决我的问题

请参阅下面列出的问题:

Passing a string value to Javascript Executor in selenium

因为这是问题的继续。

有人可以帮助您如何使用sendKeys,以便它不会执行任何其他操作或以任何其他方式在文本区域中设置文本。

我想设置的字符串是多行,每个字符串可以有多行,具体取决于动态生成的用户注释。

    <table><tbody><tr><td><textarea name="comment" id="comment" rows="25" cols="80" onfocus="this.rows=25"></textarea>
        <br><div class="knob-buttons">
      <input type="submit" value="Save Changes" id="commit">
    </div>

        <table id="bug_status_bottom" class="status" cellspacing="0" cellpadding="0">
          <tbody><tr>
            <th class="field_label">
              <a href="page.cgi?id=fields.html#bug_status">Status</a>:
            </th>
            <td><div id="status"><input type="hidden" id="bug_status_dirty">
        <select id="bug_status" name="bug_status">
            <option value="REOPENED" id="v7_bug_status">REOPENED</option>
            <option value="RESOLVED" id="v9_bug_status" selected="selected">RESOLVED</option>
            <option value="VERIFIED" id="v11_bug_status">VERIFIED</option>
            <option value="CLOSED" id="v13_bug_status">CLOSED</option>
        </select>


        <script type="text/javascript">
        <!--
          initHidingOptionsForIE('bug_status');

        //-->
        </script>

    <noscript>&lt;br&gt;resolved&amp;nbsp;as&amp;nbsp;</noscript>

  <span id="resolution_settings"><input type="hidden" id="resolution_dirty" value="1">
        <select id="resolution" name="resolution">
            <option value="FIXED" id="v3_resolution" selected="selected">FIXED</option>
            <option value="INVALID" id="v5_resolution">INVALID</option>
            <option value="DUPLICATE" id="v9_resolution">DUPLICATE</option>
            <option value="WORKSFORME" id="v11_resolution">WORKSFORME</option>
            <option value="MOVED" id="v13_resolution">MOVED</option>
        </select>


        <script type="text/javascript">
        <!--
          initHidingOptionsForIE('resolution');
          showFieldWhen('cf_bug_fixed_on',
                'resolution', ['FIXED']);
        //-->
        </script>
  </span>

    <noscript>&lt;br&gt; duplicate</noscript>
    <span id="duplicate_settings" class="bz_default_hidden">of
      <span id="dup_id_container" class="bz_default_hidden">bug 
        (<a href="#" id="dup_id_edit_action">edit</a>)
      </span><input id="dup_id" name="dup_id" size="6" value="">
    </span>
    <div id="dup_id_discoverable" class="">
      <a href="#" id="dup_id_discoverable_action">Mark as Duplicate</a>
    </div>
</div>

<script type="text/javascript">
  var close_status_array = [
      'RESOLVED',
      'VERIFIED',
      'CLOSED'
  ];
  YAHOO.util.Dom.removeClass('dup_id_discoverable', 'bz_default_hidden');
  hideEditableField( "dup_id_container", "dup_id", 'dup_id_edit_action',
                     'dup_id', '' )
  showHideStatusItems( "",  ['',
                             'RESOLVED']);
  YAHOO.util.Event.addListener( 'bug_status', "change", showHideStatusItems,
                                ['',
                                 'RESOLVED']);
  YAHOO.util.Event.addListener( 'resolution', "change", showDuplicateItem);
  YAHOO.util.Event.addListener( 'dup_id_discoverable_action',
                                'click',
                                setResolutionToDuplicate,
                                'RESOLVED');
  YAHOO.util.Event.addListener( window, 'load',  showHideStatusItems,
                              ['',
                               'RESOLVED'] );

</script>
            </td>
          </tr>
        </tbody></table>
      </td></tr></tbody></table>

我要设置值的网页的一部分。

JavaScript用于设置文本区域的值:

((JavascriptExecutor)driver).executeScript("document.getElementById('comment').v‌​alue='"+line2"';");

0 个答案:

没有答案